3 Replies - 8294 Views - Last Post: 08 April 2010 - 02:44 AM Rate Topic: -----

#1 Grandville  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 06-October 09

Opening file in new IE Window

Posted 07 April 2010 - 04:28 AM

Hi All, i use the following line to open a URL (FilePath) passed from a link button in a new IE Window:

Response.Write("<script type='text/javascript'>window.open('" + FilePath + "','_blank');</script>");

However the URL can either be a http://..... like the one above which currently works, or it can be a server file location (sv-g-sfs......)

I have an if statement that determines what type of File Path it is and tried to use the following line if the file is a server file path rather than a http:

Response.Write("<script type='text/javascript'>window.open('~/Temp/Doc_" + ID.ToString() + "','_blank');</script>");

But this causes an error. Any ideas?

The line below works but opens it in the same window which i dont want:

//Response.Redirect("~/Temp/Doc_" + ID.ToString());

Is This A Good Question/Topic? 0
  • +

Replies To: Opening file in new IE Window

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Opening file in new IE Window

Posted 07 April 2010 - 04:52 AM

moved to ASP.Net
Was This Post Helpful? 0
  • +
  • -

#3 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 421
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Opening file in new IE Window

Posted 07 April 2010 - 07:27 AM

You are going to need to convert the path into an URL that the client can use. Use the ResolveClientUrl to covert it.

Response.Write("<script type='text/javascript'>window.open(" + ResolveClientUrl(" + '~/Temp/Doc_" + ID.ToString() + "'") + ",'_blank');</script>");

Was This Post Helpful? 0
  • +
  • -

#4 Grandville  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 06-October 09

Re: Opening file in new IE Window

Posted 08 April 2010 - 02:44 AM

Thanks for your reply Jayman but i tried your line and it causes an error. I think i explained my problem slightly wrong in the first place also! Its not the filepath that i actually try to open, i run SQL that retrieves a blob that has been created from the filepath (rules dictate we can not open the file path directly so a work around was introduced whereby the files are all turned into blobs overnight). The code is below.
If there is no way to open the file in a new browser window is it possible to get the Office/Adobe (for pdf's) Application itself to open the file? For example if i open a .doc file i am presented with a dialog box to open or save the word file but when i click open it opens in the browser instead of actually in the Microsoft Word application. ANY ideas would be great!

 MemoryStream ms = null;
            String strConnection = Session["ConnectionString"].ToString();

            String strSQL = "SELECT TOP 1 LD_Image " +
                        "FROM Linked_Documents_Images WITH (NOLOCK) " +
                        "WHERE Link_To_LD_ID =" + ID.ToString() + "";
            cNetDAL objDAL = new cNetDAL(strConnection, cNetDAL.Providers.SqlServer);
            byte[] PDFData = (byte[])(objDAL.ExecuteScalar(strSQL, CommandType.Text, cNetDAL.ConnectionState.CloseOnExit));

            String s = FileName;
            String type = s.Substring(s.Length - 3);

            if (PDFData != null)
            {

                String apppath = System.AppDomain.CurrentDomain.BaseDirectory.ToString();
                String docpath = apppath + "Temp\\Doc_" + ID +"." + type.ToString();

                //create pdf in temp folder
                using (FileStream file = new FileStream(docpath, FileMode.Create, FileAccess.Write))
                {
                    ms = new MemoryStream(PDFData);
                    file.Write(PDFData, 0, PDFData.Length);
                    BinaryReader br = new BinaryReader(ms);
                    //Document document = new Document(br);
                }

                Response.ContentType = "Application" + type.ToString();
                Response.Write("<script type='text/javascript'>window.open(" + ResolveClientUrl(" + '~/Temp/Doc_" + ID.ToString() + "'") + ",'_blank');</script>");
            }
        }


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1