Hi,
Please go really slowly with your answer 'cos I'm a really slow reader. Oh yeah - and I've had just 2 days of XML experience !! (the c# bit is ok though).
I've created an application in C# using CSExpress2005 - now I am in the process of creating the download website to publish this and other files (.rtf for help files, .xml for charts, and a notepad.txt file). Each group of files, the program (zipped ?), the help files, and the charts will be made available as seperate downloads. All these files currently sit as real files on my machine i.e. they're not sat in a DB or anything. I've got the website sort of more or less sussed,( I ripped the personal website starter kit to bits and reconfigured and added a few pages ). Strangely the VWD2005 tutorial video doesn't mention downloading files (I guess 'cos that is all second nature to website people). yeah, I know the aspx pages are a downloaded file.
Can someone please give me the general idea of how to go about this or maybe point me in the direction of some tutorial that exists in some place?
Thanks (well, it does say no question too trivial )
I think I understand your question, but then I think I must be wrong?
You mean you want to provide your users the ability to download the files? Why not just provide a http link to the files for them to download?
If you need to provide security to those logged in only, simply create an httphandler class and check if User.IsAuthenticated and if so, return the file in the response stream. You can google "httphandler download file asp.net" for that
not sure if i answered your question, help that helps.
Thanks Liming,
I guess that is the nuxx of what I am searching for - 1) How to create a HTTP link to my files? 2) Where are the files supposed to reside within the Web Development environment? ie is there some folder that needs to be created? ( the Navigate URL only stays within the Web Dev environment from what I can see and I cant seem to find a place in there for them to reside).
As far as the download page is concerned - I think I've got that covered - I'm hoping to keep the download page hidden until after login - ie by using the login view. Is there another way ? such as some programmable item in ASP.net security , like the way the 'manage users' only appears for admin users?
I normally put my files in a directory outside of my webserver's root, though with ASP.NET 2.0, I put some in /APP_DATA. Tthis way others can't type the filename in the browser.
Crreate an httphandler for the download files (you can google on that) that takes the filename as a parameter. Base on the file name, read it from the disk and stream it back to the browser. On your html page, simply link to it by doing something like
<a href="http://links.10026.com/?link=mydownload.ashx?filename=myfile.zip">MY File</a
hope that helps.
You can also use the class System.Net.HTTPWebRequest to download files from an arbitrary location. You can simply put a file on the website eg: http://www.google.com/intl/en_ALL/images/logo.gif
and do the following:
This code will download Google's logo and save it to a file on disk at C:\logo.gif.
System.Net.HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.google.com/intl/en_ALL/images/logo.gif"); Stream bStream = req.GetResponse().GetResponseStream(); System.Drawing.Bitmap bmpImage = (Bitmap) Bitmap.FromStream(bStream); bmpImage.Save("C:\\logo.gif");
0 comments:
Post a Comment