Hi All,
I want to write an output from a page into a txt file which resides in a samba share. There are two Scenarios.
1. On development machine.
2. On hosting server.
Now i am only concerned about development machine. In my asp.net application i have a page, the output should be written to a txt file in a samba share. it is in network.
I have no access to samba share. we have created a local user with all access to this share. When i try loging into samba share in windows run command and executing my code it works fine.
But if log off from samba share and again execute the code it will throw "Unknown username or bad password error."
Here is my code.
New Update
I logged into samba share with correct credentials in windows run command and then i executed the code with false credentials, Then also it works fine. I am totally confused now.
System.Net.WebResponse response;
String strMSG = string.Empty;
WebRequest myReq = WebRequest.Create("file://inecsamba/hardware/hosts.txt");
myReq.PreAuthenticate = true;
NetworkCredential networkCredential = new NetworkCredential("username", "pwd");
myReq.Credentials = networkCredential;
myReq.Method = "POST";
try
{
using (var sw = new StreamWriter(myReq.GetRequestStream(), System.Text.Encoding.ASCII))
{
sw.Write("tect to be written");
}
response = myReq.GetResponse();
strMSG = string.Format("{0} {1}", response.ContentLength, response.ContentType);
}
catch (Exception ex)
{
strMSG = ex.Message;
Label2.Text = strMSG;
}
this username and pwd is localaccount username and password.
Please help me in this . I don't know more about network connection.
If needed i can provide much more details.