我試圖通過在需要的地方注入userID
和portalID
來構建目錄路徑。如何在C#中使用轉義字符構建字符串
string userID = HttpContext.Current.Request.Params["userID"];
string portalID = HttpContext.Current.Request.Params["portalID"];
// This is the acutal path ---> string folderName = @"C:\DotNetNuke 8.0\Portals\0\Users\017\17\17";
string folderName = "c:\\DotNetNuke 8.0\\Portals\\" + portalID + "\\Users\\0" + userID + "\\" + userID + "\\" + userID;
HttpContext.Current.Response.Write(folderName);
// This is what's returned ---> c:\DotNetNuke 8.0\Portals\\Users\0\\
我覺得找你e尋找「逐字串文字」,也就是引號前面的「@」符號。檢查參考:https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/string – UnholySheep
userID和portalID可能爲空。要構建路徑,請查看Path.Combine(...),而不是使用字符串連接。 – linac
請閱讀[問]並解釋(用語言,而不是代碼中的註釋),你期望看到什麼以及你實際看到了什麼。同時解釋你所嘗試過的。使用調試器檢查變量可以幫助你很多。 – CodeCaster