I got a C# windows forms app where it reads a text file from a sharepoint, then does some modification and then it should update. Sounds simple but I am kind of lost with the stream/credentials use. So far I am able to read without any problem (so there is no credentials problem) but when trying to do this:
System.IO.StreamWriter file2 = new System.IO.StreamWriter(s);
And this is the error I am having:
- n {"Stream was not writable."} System.Exception {System.ArgumentException}
Code:
WebRequest request = WebRequest.Create(rutaCoinsDiscount);
request.Timeout = 30 * 60 * 1000;
request.UseDefaultCredentials = true;
request.Proxy.Credentials = request.Credentials;
WebResponse response = (WebResponse)request.GetResponse();
using (Stream s = response.GetResponseStream())
if (s != null)
{
string linea;
System.IO.StreamReader file = new System.IO.StreamReader(s);
while ((linea = file.ReadLine()) != null)
{
coinsLines[contador] = linea;
contador++;
if (linea != "") {
lastline++;
}
}
file.Close();
int index2 = coinsLines[1].IndexOf(":") + 1;
string Gcoins = coinsLines[1].Substring(index2);
giveBalanceOld = Convert.ToInt32(Gcoins);
giveBalanceOld = giveBalanceOld - giveAmount;
coinsLines[1] = "GIVE:" + giveBalanceOld.ToString();
coinsLines[lastline] = DateTime.Today.ToString("d") + "+GIVE to:+" + destination + "+Coins: " + giveAmount;
System.IO.StreamWriter file2 = new System.IO.StreamWriter(s);
for (int j = 0; j < lastline; j++)
{
file2.WriteLine(coinsLines[j]);
}
file2.Close();