簡單檔案的上傳與儲存
本文簡單地使用Asp.net中FileUpload元件實現簡單的檔案的上傳
頁面前臺部分
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><asp:FileUpload ID="myFile" runat="server" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" />
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--><asp:FileUpload ID="myFile" runat="server" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px" />
附件實體類
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> ///
/// 附件,加一個實體化類是為了用orm的方式儲存附件物件,屬性根據自己需要新增
///
public class Attachment
{
public int Id { get; set; }
public string Name { get; set; }
public string ExtendName { get; set; }
public long Size { get; set; }
public int IsUsed { get; set; }
public string Descript { get; set; }
public byte[] Content { get; set; }
}
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
--> ///
/// 附件,加一個實體化類是為了用orm的方式儲存附件物件,屬性根據自己需要新增
///
public class Attachment
{
public int Id { get; set; }
public string Name { get; set; }
public string ExtendName { get; set; }
public long Size { get; set; }
public int IsUsed { get; set; }
public string Descript { get; set; }
public byte[] Content { get; set; }
}
頁面後臺程式碼,頁面上傳按鈕的單擊事件中新增程式碼,呼叫如下函式
<!--
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->void saveToDataBase()
{
string fileName = myFile.FileName;
string fileType = myFile.PostedFile.ContentType;
long size = myFile.FileContent.Length;
string descript = myDescript.Text;
//new一個實體物件
Attachment attachmentObj = new Attachment();
attachmentObj.Id = 0;
attachmentObj.Name = fileName;
attachmentObj.ExtendName = fileType;
attachmentObj.Size = size;
attachmentObj.Descript = descript;
attachmentObj.Content = myFile.FileBytes;
//orm方式儲存附件物件,如NHibernate等
save(attachmentObj);
//其他處理程式碼,或註冊客戶端指令碼事件或語句
}
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->void saveToDataBase()
{
string fileName = myFile.FileName;
string fileType = myFile.PostedFile.ContentType;
long size = myFile.FileContent.Length;
string descript = myDescript.Text;
//new一個實體物件
Attachment attachmentObj = new Attachment();
attachmentObj.Id = 0;
attachmentObj.Name = fileName;
attachmentObj.ExtendName = fileType;
attachmentObj.Size = size;
attachmentObj.Descript = descript;
attachmentObj.Content = myFile.FileBytes;
//orm方式儲存附件物件,如NHibernate等
save(attachmentObj);
//其他處理程式碼,或註冊客戶端指令碼事件或語句
}
後面的話:
當然如果想做得比較完美的話,
1)首先在客戶端可以新增一些驗證,什麼檔案允許新增,伺服器端也要有一些驗證。
2)多個檔案同時上傳等
3)Ajax進度條等
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-462650/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SpringMVC 單檔案上傳與多檔案上傳SpringMVC
- 上傳檔案到七牛雲端儲存的java api一個簡單的demo實現JavaAPI
- nodejs 使用七牛雲端儲存上傳檔案NodeJS
- 單個檔案上傳和批量檔案上傳
- spring mvc(註解)上傳檔案的簡單例子SpringMVC單例
- linux下簡單的傳送與接受檔案Linux
- 簡單2步就能將大量檔案歸類儲存
- 簡單介紹nacos單機本地配置檔案儲存位置方式
- 最程式碼的上傳的程式碼檔案儲存什麼地方呢?
- 使用nodejs+express完成簡單的檔案上傳功能NodeJSExpress
- [Vue]寫一個簡單的檔案上傳控制元件Vue控制元件
- input file簡單實現限制上傳檔案的型別型別
- python寫的FTP簡單上傳下載檔案薦PythonFTP
- php單個檔案上傳PHP
- 檔案的上傳與下載
- Django檔案上傳 -- 適用於單一小檔案上傳Django
- 塊儲存 檔案儲存 物件儲存物件
- YII2檔案上傳驗證,簡單封裝封裝
- 如何獲取HDFS上檔案的儲存位置
- 使用axios上傳檔案到阿里雲物件檔案儲存伺服器ossiOS阿里物件伺服器
- Vue封裝一個簡單輕量的上傳檔案元件Vue封裝元件
- 檔案上傳與下載
- 實現簡單的csv檔案上傳和bootstrap表格的下載boot
- 檔案儲存
- post 表單大檔案上傳
- WebView上傳檔案的深坑與研究WebView
- php檔案上傳之多檔案上傳PHP
- SpringMVC檔案上傳下載(單檔案、多檔案)SpringMVC
- Nginx|構建簡單的檔案伺服器(mac) 續-FastDFS安裝(mac)|檔案儲存方案Nginx伺服器MacAST
- git的簡單上傳Git
- SpringBoot整合阿里雲OSS物件儲存實現檔案上傳Spring Boot阿里物件
- PHP實現單檔案、多檔案上傳 封裝 物件導向實現檔案上傳PHP封裝物件
- 如何實現檔案傳輸系統的多儲存
- 檔案系統儲存與oracle資料庫儲存對比Oracle資料庫
- 檔案上傳之三基於flash的檔案上傳
- 揭秘|國內影視檔案傳輸的真相,跨境檔案傳輸更不簡單
- jqm檔案上傳,上傳圖片,jqm的表單操作,jqm的ajax的使用,jqm檔案操作大全,檔案操作demo
- IPFS的檔案儲存模式模式