首页 > 编程 > .NET > 正文

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

2024-07-10 13:20:07
字体:
来源:转载
供稿:网友
在web.config中添加:
<httpModules >
<add 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();
}

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表