How do I create a filename for the download?

I am making a custom asp.net file manager. all file information stored in a SQL Server table. My table is here

Table tFile(
FileID uniqueidentifier,
FileName nvarchar(50),
Extension nvarchar(50))

      

Upload process: First I insert the table row and then I upload the file to the server. The file was then renamed to FileID (GUID value). For example: 4a6327c4-0596-4949-a5f2-a639e934d534.JPG

The entered table row is like this

4a6327c4-0596-4949-a5f2-a639e934d534 | image1 | JPG

And a file on the server like this

www.domain.com/aa/Files/4a6327c4-0596-4949-a5f2-a639e934d534.JPG

My problem is loading the current file, 4a6327c4-0596-4949-a5f2-a639e934d534.JPG

named file. I needimage1.JPG

When any user uploads the current file, how to generate the current filename for a common filename like 'image1.jpg'

+2


source to share


1 answer


You have a download.aspx page that takes an image GUID as a query string parameter. Then you can search this value in the database to get the file path and send it to the browser like this:

Response.AddHeader("Content-Disposition", "attachment;filename=image1.jpg");
Response.ContentType = "image/jpeg";
Response.WriteFile(pathToFileOnYourServer);

      



You can dynamically create the filename = image1.jpg part to call the image you like.

+9


source







All Articles