WebClient wc = new WebClient();
wc.UploadFile("http://localhost:4953/AshxAllEvent/UpFileImage.ashx", "POST", result2[0].ToString());
//result2[0]文本本地绝对路径
//即C:\\Documents and Settings\\Administrator\\桌面\\Image\\热度趋势.png
UpFileImage.ashx:
try
{
HttpFileCollection postedFile = context.Request.Files;
if (postedFile.Count>0)
{
string savepath = "";
string tempPath = "";
tempPath = System.Web.HttpContext.Current.Server.MapPath("..\\Temp\\");//System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
savepath = tempPath; //context.Server.MapPath(tempPath);
string filename = postedFile[0].FileName;
string sExtension = filename.Substring(filename.LastIndexOf('.'));
if (!Directory.Exists(savepath))
Directory.CreateDirectory(savepath);
string sNewFileName = filename.Substring(0,filename.IndexOf("."));
postedFile[0].SaveAs(savepath + @"\" + sNewFileName + sExtension);
context.Response.Write(tempPath + sNewFileName + sExtension);
context.Response.StatusCode = 200;
}
}
catch (Exception ex)
{
context.Response.Write("Error: " + ex.Message);
}