Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Server.MapPath to save a file
    text
    copied!<p>At the moment, I am saving my file to a directory hard coded in my code:</p> <pre><code>var filePath = Path.Combine(@"C:\users\my documents\github\project\source\project\App_Data\stored\", package.Id + ".zip"); </code></pre> <p>But I need to save my file using Server.MapPath .... Like: </p> <pre><code>FileInfo userFile = new FileInfo(Path.Combine(Server.MapPath("~/App_Data/stored"), package.Id)); </code></pre> <p>The complete function:</p> <pre><code> public void CompressAndDeleteSources(FlinkeMailPackage package) { var filePath = Path.Combine(@"C:\users\my documents\github\project\source\project\App_Data\stored\", package.Id + ".zip"); using (ZipFile zipFile = new ZipFile(filePath)) { foreach (var file in package.FlinkeMailFileList) { string bestandsNaam = @"C:\users\my documents\github\project\source\project\App_Data\uploads\" + file.OriginalName; zipFile.AddFile(bestandsNaam); } zipFile.Save(); } foreach (var file in package.FlinkeMailFileList) { var filePathToDelete = @"C:\users\my documents\github\project\source\project\App_Data\uploads\" + file.FileName; File.Delete(filePathToDelete); } } </code></pre> <p>But when I am trying to use <code>Server.MapPath("~/App_Data/stored")</code> it doesn't know what server is</p> <p><strong>EDIT</strong></p> <p>I can use it like: <code>HttpContext.Current.Server.MapPath("~/App_Data/stored");</code> But i can't use <code>package.Id + ".zip"</code> with it like example: <code>var savePath = HttpContext.Current.Server.MapPath("~/App_Data/stored"),package.Id + ".zip"));</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload