Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I write below code for write something in a file that uploaded in a url.

C#
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://domain/filename");
HttpWebResponse Response = (HttpWebResponse)request.GetResponse();
Stream file=Response.GetResponseStream();
StreamWriter wr = new StreamWriter(file);
wr.WriteLine("salam");

but it have An unhandled exception in line
C#
StreamWriter wr = new StreamWriter(file);

can anybody help me?
Posted
Comments
Richard MacCutchan 1-Sep-14 3:12am    
What is the value in file when the exception occurs?
Karim Pazoki 1-Sep-14 3:17am    
I have an empty file in http://domain/filename
I wanna to write in it.
Richard MacCutchan 1-Sep-14 3:30am    
Very interesting, but you still have not answered the question.
Karim Pazoki 1-Sep-14 3:54am    
https://webdeveloper.box.com/s/qbt1itrhkie95o3qvmm7
this image show the values.
Richard MacCutchan 1-Sep-14 3:58am    
No, it doesn't.

1 solution

C#
using System.IO;  // in head
using System.Net;

C#
private void button1_Click(object sender, EventArgs e)
 {
      string remoteFileUrl=@"http://img1.tebyan.net/big/1393/05/10815525515518876156213521208177619316289.jpg";  // or address
      string localFileName = @"C:\someImage.jpg";

     WebClient webClient = new WebClient();
     webClient.DownloadFile(remoteFileUrl, localFileName);
     StreamWriter wr = new StreamWriter(localFileName); // or appand=true
     wr.WriteLine("salam");
     wr.Close();
 }
 
Share this answer
 
Comments
Karim Pazoki 1-Sep-14 4:22am    
thanks majid.
But I don`t wanna to download file and edit local file! I wanna edit file that is at "http://domain".
majid torfi 1-Sep-14 8:38am    
for server you can use this tip :
using(FileStream os = new FileStream(Server.MapPath("/output/asdasdasd.ico"), FileMode.Create))
{
var ic = MakeIcon(iconbitmap, 16, false); /// function returns an icon
ic.Save(os);
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900