Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
In my web app, i use webclient class for preview document. But when i toggle (F12) to simulate mobile view (as i used bootstrap), my preview document does not work.
What should i do?

What I have tried:

This is my button click event which is working at web browser view. Means preview document is loaded.
But in mobile view, after button click , nothing happened and preview document is not loaded.

string FilePath = Server.MapPath(Path.Combine(folder,name));
            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);
            }
Posted
Updated 29-Sep-20 21:58pm

1 solution

You're loading a file from the same server, so there's no need to use WebClient at all. Just use:
C#
string filePath = Server.MapPath(Path.Combine(folder, name));
Response.ContentType = "application/pdf";
Response.TransmitFile(filePath);
The issue of the file not appearing is nothing to do with your server code; it's a browser issue. Try loading the file on a real mobile device. If it still doesn't work, then there's a problem with your file.
 
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