Perhaps you are hung up on how to actually write to a file in C#?
List<String> lineList = new List<String>();
lineList.Add("search");
lineList.Add("searchtext_val=");
lineList.Add("doc_type=customSearchParameter");
lineList.Add("text=");
lineList.Add("cat=hardcoded");
lineList.Add("subcat=hardcoded");
Then you need to make the file (this example does not name the file using GUID, but depending on your situation, you may need this if you have multiple users running this program at the same time).
System.IO.File.Delete(Server.MapPath("~/folderInRootOfSite/example.txt")); //This will delete the file if found (in case there is a lingering old version of this file still out there). This will not throw an error if the file is not there, but will delete it if it is.
var outputFile = System.IO.File.AppendText(Server.MapPath("~/folderInRootOfSite/example.txt"));
foreach(var lineVal in lineList)
{
outputFile.WriteLine(lineVal);
}
outputFile.Close(); //This line is so necessary that if you forget to include it, the process will not close and will even prevent some access to the file and will even prevent its deletion (saying something to the effect of "this file is open in another program, etc., etc., etc.").
//Now the file is saved in "~/folderInRootOfSite/example.txt".
//This is where you would have to either utilize this file from the server or perhaps write an html page and utilize JavaScript on the client-side, however, I'm not sure what functionality, if any, you will be able to use from the client-side (especially without ActiveX).
//Once you are done with whatever, don't forget to delete the file if you want it cleaned up after this process.
System.IO.File.Delete(Server.MapPath("~/folderInRootOfSite/example.txt"));
Then, if you do want to execute it with the default associated program from the server (the server will be the machine that runs it), use:
string filePath = Server.MapPath("~/folderInRootOfSite/example.txt");
System.Diagnostics.Process.Start(filePath);
However, I find it doubtful that this will really be what you want. I have heard that you can "upload a file to the browser" (I'm not sure if it was worded right, when I read it, but...) but I am not sure if you can do this, how to do this, or where any good documentation is on this.
I realize that this probably won't totally solve your issue, but I will be happy to append more to this answer as you inform me of whatever ever else may be hanging you up.
----------UPDATED INFORMATION--------------
In order to use the download manager of the browser for your files, all you need to do is to path to said file in a regular <a>
tag, like this:
<a href="/fileDirectory/file.doc">Click here for file download!</a>
Which will normally work fine, however, there is still one more thing to consider. Most browsers have built in viewers for certain types of files (.pdf
s are a good example), which will, instead of using the download manager, simply open up the file to be viewed within the browser.
There are a few ways to force the download manager, however, which I will share with you from the following site: http://www.tipsandtricks-hq.com/forum/topic/force-a-file-to-download-instead-of-showing-up-in-the-browser
How Browsers Work With File Downloads Usually when a user goes to a
file URL (for example: a download link), the file will show in the
browser if the browser supports it. Image files like jpg, png, gif
etc. will almost always show in the browser. Archive files like zip,
tar, gzip etc. will always be downloaded. Some file types show up in
some browsers but not others depending of if the browser can read the
file or not. For example, Internet Explorer (IE) will usually try to
show Microsoft Word files (doc and docx) in the browser, while most
other browsers will download it. Google Chrome has its own PDF
converter and it will try to convert a PDF file and render it in the
browser.
The key thing to understand is that some browsers maybe able to read a
particular file type based on the addons you have installed for that
browser while others may not be able to. If a browser can read the
file type it will show it in the browser. If the browser cannot read a
file type it will force a download to the hard disk. Usually this is
not an issue since the users can save the file to there computer after
it is shown in the browser.
How to Force a File Download For All My Files Some users prefer that
all the files should be forced downloaded (no showing in the browser).
There are a few things you can do to ensure that.
Option 1: The easiest solution is to put your file (example: a PDF
file, a movie file) inside a zip file if possible (If you are using
the PDF Stamper plugin then you can't do this unfortunately). Browsers
cannot read zip file so it will force a download. Most computer users
know to unzip the file and get the content from inside.
Option 2: Most browsers have a settings where it lets the users
specify if they want to force download a certain type of files (for
example: a pdf file). You can instruct your users to use this option
if you think it will help them (again this is common knowledge and
most internet users know this).
Option 3: You can add the following lines of code in your .htaccess
file of your server to force a download of a particular file type from
your server (in this example it is for PDF file types):
<FilesMatch "\.(?i:pdf)$">
ForceType application/octet-stream
Header set Content-Disposition attachment
</FilesMatch>
You can change "pdf" to any other file type based on your need
(example: doc).
Now, that having been said, it seems that in your example you used some kind of custom file extension (I think), which would, of course, not be recognized by any browser, so you may not need to do anything extra after simply setting up the <a>
tag. This answer, however, seems almost too easy, so I'm not sure if this is actually what you're after or not.
So, if I understand your situation correctly, you should be able to set up such a tag, and after it is downloaded by your user, check where it was downloaded to and execute such a file with C# (you might need AJAX at some point during this process, but I'm not really sure without delving deeper. I am also not sure, since the user will have control over where on their hard-drive the file gets saved, how to check where it was saved for future use with System.Diagnostics.Process.Start(filePath);
)
One possible location for such information involves simply detecting when the file has been downloaded, but seems pretty complex, and, tbh, I'm not sure I am quite at the level to fully understand all of this, but here is a link anyway: Detect when browser receives file download