現在需要把一個Base64的編碼轉換為圖片,然后上傳到一個文件里,但是老是出現未找到XXX路徑的一部分的問題,代碼如下:
?protected void Page_Load(object sender, EventArgs e)??????? {??????????? var base64 = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD";??????????? var path = Server.MapPath("~/App_Data/");??????????? SaveDecodingToFile(base64,path);??????? }??????? public void SaveDecodingToFile(string base64String, string fileName)??????? {??????????? using (FileStream file = new FileStream(fileName, FileMode.OpenOrCreate))??????????? {??????????????? System.IO.BinaryWriter bw = new System.IO.BinaryWriter(file);??????????????? bw.Write(Convert.FromBase64String(base64String));??????????????? bw.Close();??????????????? file.Close();??????????? }??????? }
下面是報錯的信息:
“System.IO.DirectoryNotFoundException”類型的異常在 mscorlib.dll 中發生,但未在用戶代碼中進行處理其他信息: 未能找到路徑“F:\Solution1\WebApplication1\App_Data\”的一部分。
- 2 回答
- 0 關注
- 1170 瀏覽
添加回答
舉報
0/150
提交
取消