文件上传问题,找不到文件(File Upload problem, file not found)

   IT问题网   2021-01-19 00:00:00

问 题

嗨,
我的asp.net表单,我正在尝试 to 保存图片 我的sql 数据库。问题 文件上传按钮只取名称 文件 完整路径。 我尝试 保存它,它说 file 未找到
openfiledialog span> webforms, 使用 vb.net 非常好用。

谢谢

解决方案

那是因为fileupload控件没有将文件保存到磁盘 - 它我不知道你想用它做什么。

这是我使用的代码:



  ///   lt;  摘要 gt;  
/// 将上传保存到数据库中。
/// lt; / summary gt;
/// lt; param name ="fl" gt; 包含控件下载。lt; / param gt;
/// lt; 返回 gt; 状态为字符串lt; / returns gt;
private string saveupload(fileupload fl)
{
if (fl。 hasfile)
{
尝试
{
int version = 0 ;
string filename = path.getfilename(fl.filename);
byte [] filedata = fl.filebytes;
string strcon = connectionstrings.download;
使用(sqlconnection con = new sqlconnection(strcon))
{
con.open();
// 将文件粘贴到数据库中。
使用(sqlcommand ins = new sqlcommand(" insert into dlcontent(id,filename,description,datacontent,version,uploadedon)" +
" values(@ id,@ fn,@ ds,@ dt,@ vs,@ ud)",con))
{
ins.parameters.addwithvalue(" @ id",guid.newguid());
ins.parameters.addwithvalue(" @ fn",filename);
ins.parameters.addwithvalue(" @ ds"" ");
ins.parameters.addwithvalue(" @ dt",filedata);
ins.parameters.addwithvalue(" @ vs",版本);
ins.parameters.addwithvalue(" @ ud",datetime.now);
ins.executenonquery();
}
}
return string .format(" {0}已上传,版本= {1}",文件名,版本);
}
catch (例外情况)
{
return " 无法上传文件。出现以下错误:" + ex.message;
}
}
return " 请选择一个文件。";
}


从上传按钮单击事件处理程序调用。

hy这是acode我把图像存储在文件夹中..

我也建议你使用文件夹选项becoz iu将图像存储在数据库中..然后它才能获得空间





静态字符串ext;

public void btnupload_click(object sender,system.eventargs e)

{

httppostedfile myfile = filupload.postedfile;

if(myfile!= nullamp;amp; myfile.contentlength!= 0amp;amp; myfile.filename!="")

{

if(system.io.path.getextension(myfile.filename)。tolower()!=".jpg"amp;amp; system.io.path.getextension(myfile。 filename)。tolower()!="。yuv"amp;amp; system.io.path.getextension(myfile.filename)。tolower()!=".tif"amp;amp; system.io.path.getextension( myfile.filename)。tolower()!="。thm"amp;amp; system.io.path.getextension(myfile.filename ).tolower()!="。pspimage"amp;amp; system.io.path.getextension(myfile.filename)。tolower()!="。psd"amp;amp; system.io.path.getextension(myfile.filename)。tolower()!="。png"amp;amp; system.io.path.getextension(myfile.filename)。tolower()!="。gif"amp;amp; system.io.path.getextension(myfile.filename)。tolower()!="。bmp")

{

response.write("lt; scriptgt; alert (''请选择仅图像文件')lt; / scriptgt;");

imgpicture.imageurl ="";

}

else

{

if(txtref.value!=""|| txtref.value.length!= 0)

{

ext = system.io.path.getextension(this.filupload.postedfile.filename);

string id = txtref.value + ext;

myfile.saveas(server.mappath(@"/ images /"+ id));

imgpicture.imageurl ="/ images /"+ id;



conn.open();

sqlcommand updateimage = new sqlcommand("update ack set picsize =''"+ ext +"''where refno =''"+ txtref。价值+"''",conn);

updateimage.executenonquery();

conn.close();

}

else

{

response.write("lt; scriptgt; alert(''请选择你的ref n0。首先....'')lt; / scriptgt;");

imgpicture.imageurl ="";

}

}

}

}





如果你满意那么我会发送你也可以

标签:文件上传问题找不到



分享:

  • 微信
  • QQ好友
  • QQ空间
  • 新浪微博


热门推荐

请在下拉列表中解决错误(please solve error in dropdown list)

problem please solve the error i have 2 dropdownlist. in ...

更改属性上的ReadOnly属性不起作用(Change ReadOnly attribute on property doesn't work)

problem i''ve tried to change a readonly attr ...

我如何分割我的表格(how do i split my form)

problem ok i want to split my form in half so on the left ...

将templatefield动态添加到gridview(adding templatefield dynamically to gridview)

problem give the tutorial to add template field, controls ...

在c#的帮助下导出pdf文件(Export pdf File with the help of c#)

problem how to convert more then one pdf file ...

计算中间日期并在gridview中显示它(calculate inbetween date and show it in gridview)

problem hello friends, by using date time pi ...

为它的学生项目(Project for an it student)

problem hi, i m an bsc it student ,as many of you will kn ...

单击更改图标通知(Change Icon Notify on Click)

problem is possible changer notifyicon1 on click the prog ...

如果用户已经登录,则在同一浏览器中重定向到主页asp .net c#(Redirect to Home page if user already logged in, in same browser asp .net c#)

problem i want to make application that if user in logged ...

需要帮助来使用MySqlTransaction(Need help in using MySqlTransaction)

problem hi all i would like to use mysqltransaction in my ...

如何使用VBscript导航Windows注册表树(How to navigate Windows registry tree with VBscript)

problem does anyone know how to go about navigating the w ...

silverlight内存泄漏(silverlight memory leak)

problem hi, i was creating a dependencyproperty changed w ...

如何在json中获取单个元素(How to get single element in json)

problem in wcf service i am getting json response in that ...

双击文件打开程序,如何在c#中实现(double click on file opens program, how to implement in c#)

problem usually when a program in installed, you can clic ...

如何在我添加的现有数据表中添加新列,但它是bofore行的结尾(how add new column in existing datatable i added but its is come end of the bofore rows)

problem my datatable contans two columns id value ----- ...

如何在c#.net中的现有页面中打开新网址(How to open new url in existing page in c#.net)

problem hi to all, this is mdsiddiqali.i added new page n ...

DeleteObject方法不会删除任何内容 - 请帮忙。(DeleteObject method doesn't delete anything - please help.)

problem hello. i am trying to create method that will del ...

项目模板类型在C#中使用?(PROJECT TEMPLATE TYPE TO USE IN C#)

problem edit; okay i am creating a dock for programs to r ...

如何在我添加的现有数据表中添加新列,但它是bofore行的结尾(how add new column in existing datatable i added but its is come end of the bofore rows)

problem my datatable contans two columns ; id value ---- ...

在c#和asp.net中使用LinkedIn API?(Working with LinkedIn APIs in c# and asp.net )

problem hey i was trying to design an asp.net based webs ...