2011-05-27 36 views
0

我想可以右鍵點擊一個文件(S)和「發送到」本地MSSQL數據庫。細節是,我想將文件內容存儲在「內容」欄和文件名,在「文件名」列... :)快捷方式文件添加到本地SQL數據庫

*在大多數情況下,如何在新的文件內容是HTML。

好像透過窗戶在使用的快捷方式命令shell/SQL殼牌它應該是可能的「殼:SENDTO」文件夾中。

回答

0
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | Out-Null 

$Server1 = New-Object ("Microsoft.SqlServer.Management.Smo.Server") 'SQLSERVER' 
$Server1.databases["DB"].tables["Table"].rowcount 
$RowCount = $server1.databases["DB"].tables["Table"].rowcount.ToString() 

$TotalRecords = [int]$RowCount 

$wc = New-Object system.net.WebClient 
$url = "" 

$files = @(Get-ChildItem c:\test\*.*) 

"Number of files $($files.length)" 
# Errors out when no files are found 
if($files.length -lt 1) { return } 

foreach($file1 in $files) { 
    # $txt = Get-Content($file1) 
    # $txt = $txt.Replace("'", "''") 
    # Write-Host $file1.name + " - - " + $Txt 

    $url1 = $url + $file1 
    Write-Host("URL is " + $url1) 

    $webpage = $wc.DownloadData($url1) 
    $string = [System.Text.Encoding]::ASCII.GetString($webpage) 
    $string = $string.Replace("'", "''") 

Invoke-SqlCmd -ServerInstance SERVER -Query "Insert into DATABASE.dbo.Table(text,filename) Values ('$string','$file1')"}