把word文件寫入Sqlserver

2021-04-09 06:08:45 字數 2370 閱讀 2981

//

得到提交的檔案   

stream   filedatastream   

=myfile.postedfile.inputstream;   

//得到檔案大小   

intfilelength   

=myfile.postedfile.contentlength;   

//建立陣列   

byte

filedata   

=new

byte

[filelength];   

//把檔案流填充到陣列   

filedatastream.read(filedata,

0,filelength);   

//得到檔案名字   

string

filetitle   

=myfilename.value;   

//得到檔案型別   

string

filetype   

=myfile.postedfile.contenttype;   

//構建資料庫連線,sql語句,建立引數   

sqlconnection   connection   

=new

sqlconnection(

"server=.;uid=sa;pwd=mdcija;database=testuploadfile

");   

sqlcommand   command   

=new

sqlcommand   (

"insert   into   testfiles   (myfilename,myfile,filetype)"+

"values   (@myfilename,@myfile,@filetype)

",   connection);   

sqlparameter   paramtitle   

=new

sqlparameter   (

"@myfilename

",   sqldbtype.varchar,

35);     

paramtitle.value   

=filetitle;   

command.parameters.add(paramtitle);   

sqlparameter   paramdata   

=new

sqlparameter   (

"@myfile

",   sqldbtype.image);   

paramdata.value   

=filedata;   

command.parameters.add(paramdata);   

sqlparameter   paramtype   

=new

sqlparameter   (

"@filetype

",   sqldbtype.varchar,

25);     

paramtype.value   

=filetype;   

command.parameters.add(paramtype);   

//開啟連線,執行查詢   

connection.open();   

command.executenonquery();   

connection.close();   

message.text="

你的檔案已經成功上載

";   

myfilename.value   =""

;   

string

sql=

"select   *   from   testfiles   where   id   =   '"+

request.querystring["id

"]   +"

'"

;   

sqlconnection   connection   

=new

sqlconnection(

"server=.;uid=sa;pwd=mdcija;database=testuploadfile

");   

sqlcommand   command   

=new

sqlcommand(sql,   connection);   

connection.open();   

sqldatareader   dr   

=command.executereader();   

if(dr.read())   

dr.close();   

connection.close(); 

網頁內容寫入word文件

根據html 獲取word文件內容 該函式依賴於類wordmake 該函式會分析img標籤,提取src的屬性值。但是,src的屬性值必須被引號包圍,否則不能提取 param string content html內容 param string absolutepath 網頁的絕對路徑。如果html內...

怎麼把cad檔案匯入word文件?

方法 我們把cad圖紙以的形式插 入word。方法如下 1.我們執行cad編輯器專 業版,點 擊選單欄 檔案 開啟 選項,或是按快捷鍵 ctrl o 開啟需要轉換成word檔案的cad圖紙。2.然後我們在繪圖框中,移動游標選中cad圖紙中的所 有圖元,然後在命令框中輸入 copyclip 命令或是直...

寫入word模板

1.工具類 匯出word 第一步生成替換後的word檔案,只支援docx 第三步刪除生成的臨時檔案 模版變數中變數格式 param templatepath word模板位址 param temdir 生成臨時檔案存放位址 param filename 檔名 param params 替換的引數 設...