欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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();
}