Thursday, July 9, 2009

How do i upload a file to the client using asp?

I want to create a txt on the client side (I do not want to save it on the server if this is possible), then I want to upload it to the client and from my webpage. How would I go about doing this? I only find things on how to upload to the server on the net. However, I want to upload to the client.

How do i upload a file to the client using asp?
That would be called "downloading" and would be done by giving the user a link to the file on the server.





Edit: Then make the button redirect to the file instead of using a link. The easiest way would probably just be to use JavaScript... write a function that redirects to the file you want them to download, and have the button onClick event invoke the function.
Reply:I think what you want to do is stream a binary to the client.





What I describe here, you'd put in the Button_Click event and would cause a pop-up to appear on the client screen that gives the option to save, open or cancel. Bear in mind - there is no web code that allows you to just write to a client computer - that's called a Trojan Horse (yeah, yeah -some people are stupid and let you do it, but you shouldn't write you code to assume that).





But, this code should get you moving along the path I think you want to take.





Use the Response object, just like you'd do Response.Write.


However, instead do this:


BinaryStream myStream = SomeFunctionToGetStream


Response.BufferOutput = true


Response.ClearHeaders()


Response.ClearContent()


Response.Write("content-disposition","...


Response.AddHeader("content-length", myStream.length)


Response.BinaryWrite(myStream);


Response.Flush





I'm probably missing a command or two since I'm doing this off my head - I don't write this specific type of code much - instead I just wrap it up in a class. Anyhoo - seach on BinaryWrite and those other commands and you should be able to find a real example.


No comments:

Post a Comment