|
yeah I can do all that I can put the csv file using streamwriter...i just need to know where to put the file that streamwriter creates and how do i access it!
At the moment I am attempting to place the file on the server and then redirect the browser to the file name. This isn't working for me yet however, and I am not sure that this is even the best way to do it. I was asking which is the best way.
Here is my code, so you can see where I am currently coming from, it don't work like but it should give you an idea as to where i am coming from. But don't forget I am enquiring about best practices here, not how to fix this specific bit of code.
Protected Sub btExport_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btExport.Click<br />
<br />
Dim datTable As DataTable = gvReport.DataSource<br />
<br />
' Create a directory for the file to be stored on the server<br />
' Check whether a directory exists in the first place. If not create it.<br />
If Not Directory.Exists(Server.MapPath("CSV")) Then<br />
Directory.CreateDirectory(Server.MapPath("CSV"))<br />
End If<br />
<br />
' Create a unique identifier.<br />
Dim strFileName As String<br />
strFileName = Server.MapPath("CSV") & "\" & GetTempName()<br />
<br />
Dim objStreamWriter As StreamWriter<br />
objStreamWriter = File.AppendText(strFileName)<br />
' Code to write the csv file to the writer.<br />
objStreamWriter.Close()<br />
End Sub
Cheers
Ian
|
|
|
|
|
Here's the way I've seen it done before (no idea if it's best practice - but what the hey! )
When the user clicks the button, have the database export to a temporary .csv somewhere on the server (that the user will be able to access). Then do a response.redirect as the return of the page postback giving the url of the newly created temporary file. Hey presto, the user should be presented with a file download dialog.
There's bound to be a few gotchas, the one that springs readily to my mind is that you must make sure to purge that temp directory on a frequent basis, or you'll enter a world of pain!
|
|
|
|
|
Thanks thats the way I have implemented it now. I perform the purge whenever the application start method runs. The Server is shutdown at the end of each working day so it should purge once a day. Its a right bit of a bugger tho. Esp as I haven't been able to figure out as to when the application object is created if the path of the calling webform isn't in the root then it has the potential to create CSV directories allover the shop :-S I am using MapPath to get the Path name and it just picks up the current location. nightmare! lol I am sure is will come up with something tho
Cheers
For everyone's help esp Martin!
Ian
|
|
|
|
|
how can v write html tags in asp.net +c# code??
|
|
|
|
|
you can write all your html code in a stringbuilder if you want to!
Gautham
|
|
|
|
|
Do you mean something like this ? Response.Write("<h1>This is HTML heading tag</h1>")
-- modified at 9:19 Wednesday 11th July, 2007
|
|
|
|
|
can i write the html tags in defaultpage.aspx.css???
|
|
|
|
|
regimol wrote: can i write the html tags in defaultpage.aspx.css???
Yes. You can append all your HTML tags in a string and write it to the response. Or put one literal control and assign this string to there
|
|
|
|
|
regimol wrote: defaultpage.aspx.css
.CSS indicates Cascading Style Sheet.
.CS indicates CSharp
|
|
|
|
|
Hi,
We have our application in two different servers!
Now in our application we have a page with a provison of a link, on clicking this link a new pop window opens! [this normally takes time]
Now, the problem is in one of the server even it is taking time finally you could see the contents of the pop up window.
In the other server the pop window appears with nothing loaded waits for about 10 - 15 seconds and then automatically closes.
What could be the problem, is it related some server configuration?
Gautham
|
|
|
|
|
gauthee wrote: and then automatically closes.
|
|
|
|
|
|
Hi,
I am uploading from a CSV file. The price comes through as R 100.00. On my local machine it sees it as a decimal 100.00. When I upload the file to the server, it sees it as a string, namely R 100.00. How do I convert this R 100.00 value (which is a string) to a decimal?
And why do the 2 machines see the same field as different types? Where do I go and check for this?
Regards
ma se
|
|
|
|
|
In fact, if it's a CSV file, it IS a bunch of strings, the only possible reason I can think for one machine to refuse to parse it as a number, when your code tries to do that, is regional settings ( some regions would call 100,00 a decimal number )
You need to strip the R if you want to convert to a number.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Yeah I also thought the same thing. How do I write a regular expression to remove only the numeric part, irrespective of what else is with the decimal. It can also display as R 100,00 or R100,00 or R 100.00 or R100.0. I am not familiar with regular expressions.
|
|
|
|
|
I recommend you google 'expresso' and download it, it's an awesome tool for writing regular expressions. Off the top of my head ([\d\.,]*) will capture the numeric portion of those strings. Or you could just do replace("R", "") to remove the R, if you know that's all you need to remove.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Thanks I will check it out.
|
|
|
|
|
Could somebody please advise how to add a LoginStatus control to page validation?
thanks
|
|
|
|
|
Hi Friends,Im working in C#.How can I apply CSS to my web pages...
Hi,Im Razana
|
|
|
|
|
C#, of course, has nothing to do with CSS. You apply CSS the same as you would if you were using PHP, asp, or plain HTML. C# has nothing to do with it, except that a server control has a CssClass attribute instead of the usual one.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi Graus!,How are you?,I hope you are doing good...can you give me a sample for applying it in C#,Graus
Hi,Im Razana
|
|
|
|
|
Hi.
Take it CSS
Best regard
Pathan
GOD HELP THOSE WHO HELP THEMSELVES
|
|
|
|
|
Hi all
I have 5 databases.I want to connect them at runtime as the user's choice.
is there any wayto edit web.config file at runtime to change connectionstring.it is very urgent
plz reply me.
Raghvendra Kumar Roy
|
|
|
|
|
Raghvendra Kumar Roy wrote: it is very urgent
Of course it is....
You can add as many strings to your app config as you'd like. It would make more sense to store all the strings in your app config and add the functionality to select between them.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
What i can do if i have to create anew connection string
Raghvendra Kumar Roy
|
|
|
|