ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.System.UnauthorizedAccessException: Access to the path '~/uploads/getpo/getmrr/' is denied. <p>Hi,</p> <p>You need to use Server.MapPath while creating directory.</p> <p><span style="text-decoration: underline;">C#</span></p> <pre class="brush: csharp">string getpono = &#34;123&#34;; string getmrr = &#34;1258&#34;; string getitem = &#34;4875&#34;; string getreqno = &#34;1485&#34;; for (int i = 0; i &lt; Request.Files.Count; i++) { string path1 = &#34;~/uploads/&#34; + getpono + &#34;/&#34; + getmrr + &#34;/&#34;; string path2 = &#34;~/uploads/&#34; + getpono + &#34;/&#34; + getmrr + &#34;/&#34; + getitem + &#34;/&#34;; HttpPostedFile postedFile = Request.Files[i]; string uploadFolderName = Request.Files.AllKeys[i].Contains(&#34;puzzleImageArea&#34;) ? Server.MapPath(path1) : Server.MapPath(path2); if (postedFile.ContentLength &gt; 0) { try { if (!System.IO.Directory.Exists(uploadFolderName)) { System.IO.Directory.CreateDirectory(uploadFolderName); } string fileName = Path.GetFileName(postedFile.FileName); postedFile.SaveAs(uploadFolderName + fileName); } catch (Exception) { throw; } } }</pre> <p><span style="text-decoration: underline;">VB</span></p> <pre class="brush: vb">Dim getpono As String = &#34;123&#34; Dim getmrr As String = &#34;1258&#34; Dim getitem As String = &#34;4875&#34; Dim getreqno As String = &#34;1485&#34; For i As Integer = 0 To Request.Files.Count - 1 Dim path1 As String = (Convert.ToString((Convert.ToString(&#34;~/uploads/&#34;) &amp; getpono) + &#34;/&#34;) &amp; getmrr) + &#34;/&#34; Dim path2 As String = (Convert.ToString((Convert.ToString((Convert.ToString(&#34;~/uploads/&#34;) &amp; getpono) + &#34;/&#34;) &amp; getmrr) + &#34;/&#34;) &amp; getitem) + &#34;/&#34; Dim postedFile As HttpPostedFile = Request.Files(i) Dim uploadFolderName As String = If(Request.Files.AllKeys(i).Contains(&#34;puzzleImageArea&#34;), Server.MapPath(path1), Server.MapPath(path2)) If postedFile.ContentLength &gt; 0 Then Try If Not System.IO.Directory.Exists(uploadFolderName) Then System.IO.Directory.CreateDirectory(uploadFolderName) End If Dim fileName As String = Path.GetFileName(postedFile.FileName) postedFile.SaveAs(uploadFolderName &amp; fileName) Catch generatedExceptionName As Exception Throw End Try End If Next </pre> <p>&nbsp;</p>https://www.aspforums.net:443/Threads/150196/SystemUnauthorizedAccessException-Access-to-the-path-uploadsgetpogetmrr-is-denied/https://www.aspforums.net:443/Threads/150196/SystemUnauthorizedAccessException-Access-to-the-path-uploadsgetpogetmrr-is-denied/Tue, 29 Dec 2015 02:47:06 GMT