asp.net slickupload 使用方法(文件上传)
程序员文章站
2024-03-09 14:45:29
在web.config中添加:
在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();
}
<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();
}
推荐阅读
-
asp.net slickupload 使用方法(文件上传)
-
asp.net 大文件上传 之 改版了的SlickUpload.HttpUploadModule(Krystalware.SlickUpload.dll)
-
asp.net 文件上传 实时进度
-
asp.net 2.0的文件上传(突破上传限制4M)
-
asp.net 文件上传与刷新与asp.net页面与iframe之间的数据传输
-
ASP.NET在上传文件时对文件类型的高级判断的代码
-
asp.net 模拟提交有文件上传的表单(通过http模拟上传文件)
-
asp.net 上传或下载当文件名包含有特殊字符"#"的处理
-
asp.net 文件上传 实时进度
-
Asp.Net 音频文件上传和播放代码