上传文件时出错 [英] error in uploading file

查看:95
本文介绍了上传文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在上传文件时设置错误...在我的本地计算机上工作正常,但是当我将其放在服务器上时出现错误
以下是错误:-

System.IO.DirectoryNotFoundException:找不到路径"D:\ Websites \ enefinder.com \ httpdocs \ html \ uploadfiles \ 2-2-2010-20-12-49-807icon.JPG"的一部分. System.IO.FileStream.Init(字符串路径,FileMode模式,FileAccess访问,Int32权限,布尔useRights,FileShare共享,Int32 bufferSize,FileOptions选项,SECURITY_ATTRIBUTES secAttrs) ,位于System.IO.FileStream..ctor处的字符串,msgPath,布尔bFromProxy)(位于System.IO.FileStream..ctor处的字符串路径,FileMode模式,FileAccess访问,FileShare共享,Int32 bufferSize,FileOptions选项,字符串msgPath,布尔bFromProxy). (字符串路径,FileMode模式)位于html_upload.btnUpload_Click(对象发送方,EventArgs e)处,位于System.Web.HttpPostedFile.SaveAs(字符串文件名)

为什么使用这个地址D:\ Websites

我的代码是

filename = System.IO.Path.GetFileName(filename);
FileUpload1.PostedFile.SaveAs(Server.MapPath("uploadfiles")+"\\" + d2 + filename);

path ="uploadfiles" +"\\" + d2 +文件名;
SqlConnection con =新的SqlConnection(); con.ConnectionString = ConfigurationManager.ConnectionStrings ["abc"].ConnectionString;
SqlCommand cmd =新的SqlCommand();
cmd.CommandText =插入ProCat(url)VALUES(""+ path +")";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
int结果= cmd.ExecuteNonQuery();
con.Close();
如果(结果> 0)

Response.Redirect("upload.aspx");

请帮助...

Im setting error in uploading file...Its working fine on my local machine but when i put it on server im getting error
following is the error:-

System.IO.DirectoryNotFoundException: Could not find a part of the path ''D:\Websites\enefinder.com\httpdocs\html\uploadfiles\2-2-2010-20-12-49-807icon.JPG''. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at System.Web.HttpPostedFile.SaveAs(String filename) at html_upload.btnUpload_Click(Object sender, EventArgs e)

why its takeing this address D:\Websites

my code is

filename = System.IO.Path.GetFileName(filename);
FileUpload1.PostedFile.SaveAs(Server.MapPath("uploadfiles") + "\\"+ d2 + filename );

path = "uploadfiles" + "\\" + d2 + filename;
SqlConnection con = new SqlConnection();con.ConnectionString = ConfigurationManager.ConnectionStrings["abc"].ConnectionString;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "INSERT INTO ProCat( url)VALUES (''" +path +"'' )";
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
int result = cmd.ExecuteNonQuery();
con.Close();
if (result > 0)

Response.Redirect("upload.aspx");

plz help...

推荐答案

guess0985写道:
guess0985 wrote:

path ="uploadfiles" +"\\" + d2 +文件名;

path = "uploadfiles" + "\\" + d2 + filename;



这真是丑陋.请改用Path.Combine.




This is damn ugly. Use Path.Combine instead.


guess0985写道:
guess0985 wrote:

FileUpload1.PostedFile.SaveAs(Server.MapPath("uploadfiles")+"\\" + d2 + filename);

FileUpload1.PostedFile.SaveAs(Server.MapPath("uploadfiles") + "\\"+ d2 + filename );



这行是否给出错误?你不说



Does this line give the error ? You don''t say.

guess0985写道:
guess0985 wrote:

''D:\ Websites \ enefinder.com \ httpdocs \ html \ uploadfiles \ 2-2-2010-20-12- 49-807icon.JPG''

''D:\Websites\enefinder.com\httpdocs\html\uploadfiles\2-2-2010-20-12-49-807icon.JPG''



真正的问题是,是什么使您相信此目录存在?该错误表明它没有.



The real question is, what makes you believe this directory exists ? The error says it does not.


这篇关于上传文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆