程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> ASP.NET基礎 >> asp.net slickupload 使用方法(文件上傳)

asp.net slickupload 使用方法(文件上傳)

編輯:ASP.NET基礎
在web.config中添加:
<httpModules >
<add name="HttpUploadModule" type="Krystalware.SlickUpload.HttpUploadModule, Krystalware.SlickUpload" / >
</httpModules >
2、在項目中添加對Krystalware.SlickUpload.DLL的引用。
3、在頁面上放控件:HtmlInputFile fileUpload;
4、後代碼如下:
復制代碼 代碼如下:
private void RedirectToNewUpload()
{
Response.Redirect("PhotoInfo.aspx?uploadId=" Guid.NewGuid().ToString() "&action=" strViewType "&id=" BTSID);
}
private void Page_Load(object sender, System.EventArgs e)
{
...
UploadedFileCollection parts = HttpUploadModule.GetUploadedFiles();
if (Request.QueryString["uploadId"] == null)
RedirectToNewUpload();
...
}
private void btUpload_Click(object sender, System.EventArgs e)
{
UploadedFileCollection parts = HttpUploadModule.GetUploadedFiles();
string uppath = System.Configuration.ConfigurationSettings.AppSettings["UploadPath"];
try
{
if (parts != null)
{
foreach (UploadedFile part in parts)
{
if(part.ContentLength==0)
return;
if(File.Exists(uppath part.ClientName))
{
File.Delete(uppath part.ClientName);
}
part.SaveAs(uppath part.ClientName);
Byte[] FileByteArray = new Byte[part.ContentLength]; //圖象文件臨時儲存Byte數組
FileStream fs = new FileStream(uppath part.ClientName, FileMode.Open);
fs.Read(FileByteArray,0,Convert.ToInt32(part.ContentLength));
fs.Close();
File.Delete(uppath part.ClientName);
//使用FileByteArray來保存得到的數據
}
RedirectToNewUpload();
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved