views:

130

answers:

1

I'm creating asp.net special file manager. all file information saved to SQL Server table. My table is here

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

Upload process is: First i'm insert table row and then upload file to server. Then file renamed to FileID (GUID value). For example : 4a6327c4-0596-4949-a5f2-a639e934d534.JPG

Inserted table row is like this

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

And file on the server like this

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

My problem is when i downloading current file, 4a6327c4-0596-4949-a5f2-a639e934d534.JPG named file was downloaded. I need image1.JPG

When any user downloading current file, how to generate current file name to normal filename like 'image1.jpg'

+6  A: 

Have a download.aspx page which takes the GUID of the image as a query string parameter. You can then lookup 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 build the filename=image1.jpg part to call the image anything you like.

kerchingo
Thank you very very much
ebattulga