制作“文件上传”上传表单中可选 - .NET
现在,我使用它来允许将文件移动到我们的服务器:
filUpload.PostedFile.SaveAs(Server.MapPath("~/Images/" + filUpload.FileName));
但是当我不上传文件时,它会给我一个错误:
System.IO.DirectoryNotFoundException:找不到路径'C:\ ** \ ** \ Documents的一部分\视觉工作室2010\WebSites\**\Images\'.
如何使文件上传成为可选,以便用户不必上传文件?
非常感谢
Right now, I'm using this to allow a file to be moved to our server:
filUpload.PostedFile.SaveAs(Server.MapPath("~/Images/" + filUpload.FileName));
However when I don't upload a file, it gives me an error:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\**\**\Documents\Visual Studio 2010\WebSites\**\Images\'.
How do I make the file upload optional so users don't have to upload a file?
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需检查
filUpload.FileName
是否不为空。仅当不存在时才上传。.NET 4.0:
.NET < 4.0:
Just check if
filUpload.FileName
is not empty. Only upload if it isn't..NET 4.0:
.NET < 4.0: