且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何解决错误“输入字符串格式不正确”。

更新时间:2023-09-13 14:57:10

Actually, it's fairly obvious:
string relativePath = "~/Uploads";
string absolutePath = Server.MapPath(relativePath);
string fileName = fuImage.FileName;
string fullFilePath = string.Format("{0}/{1}",absolutePath,relativePath);
fuImage.SaveAs(fullFilePath);



Why?
Assume your website root folder is "C:\Websites\Gharuboy".
So

relativePath = "~/Uploads"
absolutePath = "C:\Websites\Gharuboy\Uploads"
fullFilePath = "C:\Websites\Gharuboy\Uploads/~/Uploads"

And

fuImage.SaveAs(fullFilePath);

Will try to save as that file...
No. I think what you want is this:

string fullFilePath = string.Format("{0}/{1}",absolutePath,fileName);