Kurt
0
I set up the following test in a mini - windows app. The idea is that the code could be used in an ASP.NET project later on. The general problem here is authentication... I have all the user rights to write to the mentioned server, but I dont know how to pass my credentials allong with the write command...
The following is working: (writing to a new or overwriting an existing file locally)
not working: (Writing the file to a network share)
error:
Also, mapping the "\\10.0.0.20\files$" folder to a new drive name (for example "Z:\") and using syntax as
is not working.
Is there a way to attach some user credentials to the command, so it becomes authorized to write the file?
The following is working: (writing to a new or overwriting an existing file locally)
Code:
private void button1_Click(object sender, System.EventArgs e)
{
StreamWriter sw = null;
try
{
sw = File.CreateText(@"C:\new text files\test.txt");
sw.Write("testing the method again again");
}
catch (Exception exc)
{
MessageBox.Show(exc.ToString());
}
finally
{
if (sw != null)
{
sw.Flush();
sw.Close();
}
}
}
not working: (Writing the file to a network share)
Code:
private void button1_Click(object sender, System.EventArgs e)
{
StreamWriter sw = null;
try
{
sw = File.CreateText(@"\\10.0.0.20\files$\test.txt");
sw.Write("testing the method again again");
}
catch (Exception exc)
{
MessageBox.Show(exc.ToString());
}
finally
{
if (sw != null)
{
sw.Flush();
sw.Close();
}
}
}
error:
Code:
System.UnauthorizedAccessException: Access to the path "\\10.0.0.20\files$\test.txt" is denied.
Code:
File.CreateText(@"Z:\test.txt");
Is there a way to attach some user credentials to the command, so it becomes authorized to write the file?