After an unanswered earlier query I can now happily output the content of DataTables to csv files, the only problem now is putting them in the right place and downloading them to the user's PC.
Basically I have a requirement to display an ad-hoc report in a datagrid based on date selections, (done), and allow the user to push a button to save the file to their PC.
I can populate the page and create a CSV file of the data, and place that file in a specified path, using FileStream and StreamWriter. How do I get a pointer to the virtual directory of the web site to save the file in a folder structure below the web directory without hard coding it, (as the server is different across Business Acceptance, Development and Live), and how do I force the download dialogue to appear to the user?
Of course any technically better ways to output the file directly to a place of the users choosing wuold also be good...
Please Help Me!
Rhys

1 answers
I guess what I'm trying to say is how to I get the Relative, Absolute and Virtual paths of the current web page, (all my pages are in the same virtual directory, only images and other documents will be stored in virtual directories beneath it)...
...that's a bit more plain English anyway...
Rhys
answered 8 months ago by:
0
Still moving along...
OK, As previously mentioned I can output to a file on my Web Server using System.IO, but am now trying to output to a specified virtual directory. The code below takses a string input generated by iterating through a datatable to create a 'csv' version of it, and tries to write it to a specified virtual directory...
<CODE>
// Get virtual path from web.config
string sPath = ConfigurationSettings.AppSettings["Reports"];
// Apply ASCII encoding to obtain an array of bytes .
byte[] postArray = Encoding.ASCII.GetBytes(Test);
// Create new WebClient instance
WebClient client = new WebClient();
// Write stream
Stream postStream = client.OpenWrite(sPath + "CounterpartyHeadroom/" + Dates.GetDate() + ".csv");
//Close stream
postStream.Close();
</CODE>
However I get an Error returned on postStream.Close();
<CODE> // Well an error page actually...
Exception Details: System.Net.WebException: The remote server returned an error: (405) Method Not Allowed.
Source Error:
Line 663:
//Close stream
Line 664:
string sTesting = postStream.ToString();
Line 665:
postStream.Close();
Line 666:
Line 667:
DownloadFile(sPath + Dates.GetDate() + ".csv",true);
Source File: c:\inetpub\wwwroot\cra\frmreportcounterpartyheadroom.aspx.cs Line: 665
<CODE>
I have a feeling it's something to do with the IIS permissions setup, however I've really looked at IIS configuration before so am once again going to put my confusion in your hands.
Any help appreciated...
Rhys
answered 8 months ago by:
0
This post was imported from csharpfriends, if you have a similiar question please ask it again.
All previous members have been migrated, hope you enjoy the new platform!