Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How to preview an image before downloading from server in C# when we are having id of file in query string.

What I have tried:

how to preview an image before downloading from server in C# when we are having id of file in query string
Posted
Updated 15-Feb-16 20:51pm
v2
Comments
Sinisa Hajnal 16-Feb-16 2:38am    
Simple answer is you don't. You didn't describe what you've tried. You didn't mention anything about your code. You cannot show anything client side if it is not downloaded from the server first. What you CAN do is make the preview very small (thumbnail image) and send it as part of html (via 64base encoding)
Suvendu Shekhar Giri 16-Feb-16 3:15am    
What is use of pasting the same line once again with a different heading "What I have tried"?
If you really want help, help us to understand your problem correctly.

1 solution

I have tried same for pdf

but not able to do same in jpg

string id = Request["id"].ToString(); // getting from grid click by query string

string filename = "";
string addr = "";
string fpath = "";
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["OFcon"]);


con.Open();

string query = "select addr,filename from files where id=" + id + "";

SqlCommand cmd = new SqlCommand(query, con);
SqlDataReader rd = cmd.ExecuteReader();

if (rd != null)
{
if (rd.Read())
{
addr = rd.GetString(0);
filename = rd.GetString(1);
fpath = addr + filename;

}
}

con.Close();
string path = Server.MapPath(".");
string path1 = path + "\\" + fpath;
string viewpath = fpath;


string name = Path.GetFileName(fpath);
string ext = Path.GetExtension(fpath);
string FilePath = viewpath;
WebClient User = new WebClient();
Byte[] FileBuffer = User.DownloadData(FilePath);
if (FileBuffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", FileBuffer.Length.ToString());
Response.BinaryWrite(FileBuffer);
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900