iT邦幫忙

0

c# 路徑判定錯誤

c#

我在抓路徑時,遇到了錯誤,想請問為什麼他會抓到專案底下的目錄,而不是我指定的c槽

https://ithelp.ithome.com.tw/upload/images/20190129/2011012550KQdbQmVd.png

public string UpLoadImage(string Account, string base64data)
        {
            string sRtn = "";
            var type = "";

            type= base64data.Substring(0, base64data.IndexOf(";"));

            //base64data = base64data.Substring(base64data.IndexOf(","), base64data.Count());
            base64data = base64data.Substring(base64data.IndexOf(",") + 1);
            byte[] byteimage = Convert.FromBase64String(base64data);

            var UpDirPath = "c:\vue_image";
            if (!System.IO.Directory.Exists(UpDirPath))
            {
                System.IO.Directory.CreateDirectory(UpDirPath);
            }

            UpDirPath = Path.Combine(UpDirPath, @"\");

            if (type.Contains("jpeg"))
            {
                System.IO.File.WriteAllBytes(UpDirPath + Account + "_image.jpg", byteimage);
                sRtn = "上傳成功!";
            }
            else if (type.Contains("png"))
            {
                System.IO.File.WriteAllBytes(UpDirPath + Account + "_image.png", byteimage);
                sRtn = "上傳成功!";
            }
            else
                sRtn = "請上傳JPF檔orPNG檔,不支援其他檔案!";

            return sRtn;
        }
Homura iT邦高手 1 級 ‧ 2019-01-29 17:27:53 檢舉
你是網頁嗎?
w4560000 iT邦研究生 5 級 ‧ 2019-01-29 17:32:31 檢舉
我在做要把前端丟的bace64轉成圖檔存到server端的實體目錄c槽
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
海綿寶寶
iT邦大神 1 級 ‧ 2019-01-30 08:46:22
最佳解答
var UpDirPath = "c:\vue_image";

改成

string UpDirPath = @"c:\vue_image";

試看看

w4560000 iT邦研究生 5 級 ‧ 2019-01-30 08:48:28 檢舉

大大 謝謝你,不過我解決了
我改成

var UpDirPath = "C://vue_image";

恭喜,解決就好

我要發表回答

立即登入回答