0

I am using a web service that returns me some data. I am writing that data in a text file. my problem is that I am having a file already specified in the c# code, where I want to open a dialog box which ask user to save file in his desired location. Here I am posting code which I have used. Please help me in modifying my code. Actually after searching from internet, all are having different views and there is lot of changes in code required where as I do not want to change my code in extent. I am able to write the content in test file but how can I ask user to enter his desire location on computer?

  StreamWriter file = new StreamWriter("D:\\test.txt");
 HttpWebRequest webreq = (HttpWebRequest)WebRequest.Create(yahooURL);
                // Get the response from the Internet resource.
                HttpWebResponse webresp = (HttpWebResponse)webreq.GetResponse();
                // Read the body of the response from the server.
                StreamReader strm =
                  new StreamReader(webresp.GetResponseStream(), Encoding.ASCII);

 string content = "";
                for (int i = 0; i < symbols.Length; i++)
                {
                    // Loop through each line from the stream,
                    // building the return XML Document string
                    if (symbols[i].Trim() == "")
                        continue;

                    content = strm.ReadLine().Replace("\"", "");
                    string[] contents = content.ToString().Split(',');
                    foreach (string dataToWrite in contents)
                    {
                        file.WriteLine(dataToWrite);
                    }

                }
                file.Close();
Anirudh Agarwal
  • 655
  • 2
  • 7
  • 29
Sandy
  • 275
  • 3
  • 8
  • 25
  • have you checked here: http://stackoverflow.com/questions/4341488/how-can-i-prompt-a-user-to-choose-a-location-to-save-a-file – vysakh Sep 19 '13 at 06:25
  • There's a flaw in your view. Either the user can choose where he want's to download the file on his computer, this is somehow out of your control (browser issues). Either you want the user to choose a location on the server and that is not possible due to user not knowing your server structure and due to security issues. – Nick.T Sep 19 '13 at 06:31
  • IS the code you provided part of the web service or part of the web application that consumes the web service? The webservice by itself will not be able to prompt the user to download the file. – Jon P Sep 19 '13 at 06:33
  • Actually Now I am not having web service but yes it will be converted into webservice once I accomplish. The thing is that I just have to get data, then I have to write that data into text file.But the file's location would be specified by user. – Sandy Sep 19 '13 at 06:43

1 Answers1

0

Try this

using (WebClient Client = new WebClient ())
{
    Client.DownloadFile("http://www.abc.com/file/song/a.mpeg", "a.mpeg");
}
Arbejdsglæde
  • 13,670
  • 26
  • 78
  • 144
  • This is not Working and I am having a text file. where I will keep it's response. I mean var ll=Client.DownloadFile();. what type of data type it requires to get file? – Sandy Sep 19 '13 at 06:45