webclient 为什么不能上传文件? uriString="http://localhost/c/Upload/2_28-3-326-332_200208101436.jpg"; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 string fileName ="C://Documents and Settings//Administrator//My Documents//My Pictures//2_28-3-326-332_200208101436.jpg"; huhu.string fileName =@"C:\Documents and Settings\Administrator\My Documents\My Pictures\2_28-3-326-332_200208101436.jpg";orstring fileName ="C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\2_28-3-326-332_200208101436.jpg"; 其实你用C:/2_28-3-326-332_200208101436.jpg应该就没问题""有空格Documents and Settingsurl解析的结果是DocumentsandSettings而这个目录是不存在的! 完整解决方法:public class UpLoad:System.Web.UI.Page { /// <summary> /// 上传文件到服务器目录下的uploadfile里,并返回一个保存后的文件。 /// </summary> /// <param name="upload"></param> /// <returns></returns> public string FileUpLoad(System.Web.UI.HtmlControls.HtmlInputFile upload,string pa) {// try// { string filename=upload.PostedFile.FileName; int i= filename.LastIndexOf("."); //取得文件扩展名 string newext =filename.Substring(i); //这里我自动根据日期和文件大小不同为文件命名,确保文件名不重复 DateTime now = DateTime.Now; string newname=now.ToShortDateString().Replace("-","")+now.ToShortTimeString().Replace(":","")+upload.PostedFile.ContentLength.ToString(); upload.PostedFile.SaveAs(Server.MapPath("uploadfile\\")+newname+newext); return pa+"uploadfile\\"+newname+newext; //返回文件及路径名// }// catch(System.Exception err)// {// throw new Exception(err.Message);// } } } 你使用WebClient来上传文件,你要搞清楚一件事。那就是你的程序是在服务器上运行的。你要上传的并不是你本地的文件,而是你服务器上的。服务器上的文件对你本地文件没有操作权限。 那webclient拿来干什么?没有用了嘛,这可是webclient,客户端!,请问一下webclient有什么用? 用WebClient下载没任何问题。所以,我想,在服务器方应该有个东西来接收数据并保存到文件。这个东西是什么呢? 【Socket监听端口问题 急!!!!!!!!!!!!!!!!!】 郁闷问题,谁能告诉我为什么!!我快疯了 IBatisNet菜鸟,请教点问题! C#里有没有类似ScrollWindow可以滚动窗体内容的函数? 非C#问题,请高手帮忙! 关于页面呈现的头痛问题,是不是.net不能支持?? 怎样禁止一个窗口程序都次打开?谢谢! 关于SmtpClient类 c#net2005打包 菜鸟问题,大家一般用什么编译c# ? C#编写Windows Service 紧急提问,在线等候!
string fileName =@"C:\Documents and Settings\Administrator\My Documents\My Pictures\2_28-3-326-332_200208101436.jpg";or
string fileName ="C:\\Documents and Settings\\Administrator\\My Documents\\My Pictures\\2_28-3-326-332_200208101436.jpg";
应该就没问题""有空格Documents and Settings
url解析的结果是DocumentsandSettings
而这个目录是不存在的!
{
/// <summary>
/// 上传文件到服务器目录下的uploadfile里,并返回一个保存后的文件。
/// </summary>
/// <param name="upload"></param>
/// <returns></returns>
public string FileUpLoad(System.Web.UI.HtmlControls.HtmlInputFile upload,string pa)
{
// try
// {
string filename=upload.PostedFile.FileName;
int i= filename.LastIndexOf(".");
//取得文件扩展名
string newext =filename.Substring(i);
//这里我自动根据日期和文件大小不同为文件命名,确保文件名不重复
DateTime now = DateTime.Now;
string newname=now.ToShortDateString().Replace("-","")+now.ToShortTimeString().Replace(":","")+upload.PostedFile.ContentLength.ToString();
upload.PostedFile.SaveAs(Server.MapPath("uploadfile\\")+newname+newext);
return pa+"uploadfile\\"+newname+newext; //返回文件及路径名
// }
// catch(System.Exception err)
// {
// throw new Exception(err.Message);
// }
}
}
那就是你的程序是在服务器上运行的。
你要上传的并不是你本地的文件,而是你服务器上的。服务器上的文件对你本地文件没有操作权限。
这可是webclient,客户端!,请问一下webclient有什么用?