Note that there are some explanatory texts on larger screens.

plurals
  1. PODirectory Not Found exception when deployed to server
    primarykey
    data
    text
    <p>The goal I have is simple: From a web app, write to a folder on the D drive of a local server. When I run the code locally (in the debugger) it writes to the folder beautifully. When I publish the code to the web server it cannot see its own D drive, or shared folder. I have tried every permutation of the file path string I can imagine, including absurd ones.</p> <p>Examples:</p> <pre><code>filepath = "\\\\wsbliwad\\d\\Payroll\\PaperlessPay"; filepath = "\\wsbliwad\\d\\Payroll\\PaperlessPay"; filepath = "\\wsbliwad\d\Payroll\PaperlessPay"; filepath = "\\\\wsbliwad\\Payroll\\PaperlessPay"; filepath = "\\wsbliwad\Payroll\PaperlessPay"; filepath = @"\\wsbliwad\payroll\PaperlessPay"; filepath = @"\\\\wsbliwad\\payroll\\PaperlessPay"; filepath = @"\\wsbliwad\\payroll\\PaperlessPay"; filepath = @"\\wsbliwad\d\Payroll\PaperlessPay" </code></pre> <p>... and a host of others as well.</p> <p>Using Response.Write statements to get a sense of what's happening, if I run the code locally, I get the following feedback:</p> <pre><code>Path one = \\wsbliwad\payroll\PaperlessPay Exists = True Path two = \\wsbliwad\\payroll\\PaperlessPay Exists = True Path one = \\\\wsbliwad\\payroll\\PaperlessPay Exists = True Host Name is CPU1476 AD User is ANVILCORP\DGray </code></pre> <p>And the file writes to the folder.</p> <p>When I deploy that same code, I get a failing result:</p> <pre><code>Path one = \\wsbliwad\payroll\PaperlessPay Exists = False Path two = \\wsbliwad\\payroll\\PaperlessPay Exists = False Path one = \\\\wsbliwad\\payroll\\PaperlessPay Exists = False Host Name is WSBLIWAD AD User is ANVILCORP\dgray </code></pre> <p>No file is written.</p> <p>I've gone to the folder and explicitly granted write permissions to all the users in our group who need it, thinking perhaps it was a badly reported permissions issue. No such luck. </p> <p>One oddity I have noted is that the last line in my response.write gives me upper case letters for the domain user when I run it in the debugger, and lowercase when the code is deployed. I don't know that it should matter, but it does seem odd.</p> <p>Any ideas why the code can see the shared folder from my debugger, but not when deployed?</p> <p>For DJ KRAZE'S request below:</p> <pre><code>protected void btn_Export_Click(object sender, EventArgs e) { DateTime mCheckDate = DateTime.Parse(tb_CheckDate.Text); int mPeriod = Int32.Parse(tb_Period.Text); try { string checkDateFormat = "MM/dd/yyyy"; ReadOnlyCollection&lt;IDataRow&gt; dataRows = FlatFileExportWeb.PaperlessPay.GetPaperlessPayData(mPeriod.ToString(), mCheckDate.ToString(checkDateFormat)); if (dataRows == null) return; IDataFormat format = new SimpleDataFormat(dataRows); string filepath = ""; string machineName = System.Net.Dns.GetHostName(); if (machineName == "WSBLIWAD") { // This path does not work filepath = @"\\wsbliwad\d$\Payroll\PaperlessPay"; } else { // this path works when debugging filepath = @"\\wsbliwad\payroll\PaperlessPay"; } string filename = "PaperlessPay" + mCheckDate.ToString("MMddyyyy") + ".txt"; new FileGenerator(filepath, filename).BuildFile(format); Response.Write("&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Success!! The flat file has been written to " + filepath + @"\" + filename); } catch (Exception ex) { // Display any exceptions that may have been thrown. System.Web.HttpContext.Current.Response.Write(ex); } } </code></pre> <p>... and then...</p> <pre><code>// Absolute path with concatenated filename string mFilenameWithPath; /// &lt;summary&gt; /// Constructs a FileGenerator instance pointing to filepath\PaperlessPay\filename. /// Will delete pre-existing file at this location. /// &lt;/summary&gt; public FileGenerator(string filepath, string filename) { if (!Directory.Exists(filepath)) throw new DirectoryNotFoundException(filepath); mFilenameWithPath = filepath + @"\" + filename; if (File.Exists(mFilenameWithPath)) File.Delete(mFilenameWithPath); } /// &lt;summary&gt; /// Given an IDataFormat instance, BuildFile builds an output string. /// It will then write this output string to the file specified within /// the class, as passed into the constructor. /// &lt;/summary&gt; /// &lt;param name="format"&gt;&lt;/param&gt; public void BuildFile(IDataFormat format) { // Make sure the format exists if (format == null) return; // Collect output string, and // write the string to filepath. using (StreamWriter writer = File.CreateText(mFilenameWithPath)) writer.Write(format.Build()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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