2
Answers

HELP -> open PDF file with "#search=word" option by using Response.WriteFile

Sergey

Sergey

13y
10.3k
1
Hello . I hope someone can help me :)

 I need to open a pdf file like :
 www.mysite.com/myfile.pdf#search=word
 This opens the file and selects the first found word "word".
 It is working perfect ... but I need to do the same but if the file is located in app_data folder ... or in a database ...

The problem is that '#' is replaced with '_'.
It might be that the approach is wrong in general ... any suggestions ?
Thanks !

here is the code :

System.IO.FileInfo file = new System.IO.FileInfo(MapPath("~/app_data/Files/" + "myfile.pdf"));

        if (file.Exists)
        {
            Response.Buffer = true;
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
           
            string fname = "MyFile.pdf#search=word";
            string disp = String.Format("attachment; filename={0}", fname);

            Response.AddHeader("Content-Disposition", disp);
            Response.Charset = "UTF-8";
            Response.AddHeader("Content-Length", file.Length.ToString());
            Response.ContentType = "application/pdf";
            Response.WriteFile(file.FullName);

            Response.End();
        }


Answers (2)