Writing output file using C#
I never did this process before...i am new to C#.
I get out file downloadable from IE...
Process p =newProcess();
p.StartInfo.FileName ="iexplore.exe";
p.StartInfo.Arguments = rptUrl.appURL;
p.Start();
I want to write this output file in a network directory and rename file to a meaningful name with date appended. How can i do. Looking for C# sample code can do.
Here is my network directory... c:/source/rptresult/file
Please post all resources and help.
1. what do you mean by network drive? usually a mapped drive is like @"y:\test\", you write your file just like local, or it's like @"\\machinename\sharedpath\subpath", which still works more or less like a local path.
2. if it's a simple URL from which you want to download file from, I suggest you try WebClient class, which is quite easy to use. or it could be a lot more complicated.
3. when you download the file from a stream, basically you can name it what ever you want. unless the file is already saved some where with a name, then you can use File.Move to rename it after it's been downloaded.
I get my file from a url....now it opens IE and download.
see like this...
Process p = new Process();
p.StartInfo.FileName = "iexplore.exe";
p.StartInfo.Arguments = rptUrl.appURL;
p.Start();
i want to save this file to a folder...how can i do?....i like to rename the file before saving or after saving which easy.
Please help me with code sample.
how will i combine this code?.
This is my code i found from sample...working fine.
Process p = new Process();
p.StartInfo.FileName = "iexplore.exe";
p.StartInfo.Arguments = rptUrl.appURL;
p.Start();
This is VB.net code i got online.
Dim webClient As New System.Net.WebClient
webClient.DownloadFile("http://www.dotnetspider.com/index.aspx", "C:\spider.html")
i want to save the file in a folder...how i combine the code and write in C#.
Please help me...my coverted code is not working for me.
i included
using System.Net;
in my project....
then output area i wrote....
webClient.DownloadFile(
"rptUrl.appURL", "C:\csv.txt")my modified code is not working....what is wrong?.
I modified the code and combined it...
WebClient
user = new
WebClient(); string
uri = "rptUrl.appURL"; string
fname = "storeData.txt";Console.WriteLine("Downloading data from " + uri+ " to " +fname);user.DownloadFile(uri,fname);
i am having some problem with this code...
1. My url is dynamic url......
string uri = "rptUrl.appURL";
how will i pass a dynamic url to user.DownloadFile() method?.
2. I want to write to some folder with different name...how can i do?.
string fname = "c:\storeData.txt";
when i done this...i am getting an error.
Please help me...
Error i am getting....
Downloading data from rptUrl.appURL to storeData.txt
Could not find file 'C:\AppDir\bin\Debug\rptUrl.appURL'
My dynamic url is not translated to real value. Why so?. Variable is not replacing with real value.
Let me tell you, what i really trying to do.
i got a url in a variable called "rptUrl.appURL".
value of rptUrl.appURL is https://www.microsoft.com/app/report_data.csv
This csv file i want to save to a local folder...
How can i do using C# code?.
You're passing the string "rptUrl.appUrl", not the variable (note the quotation marks in your code). So this should work:
Code Snippet
webClient.DownloadFile(
rptUrl.appURL, "C:\csv.txt"); (Of course this requires write access to C:\ — you may want to use a more appropriate directory for testing.)
Please have a look at the sample code for WebClient.DownloadFile().