Click here to Skip to main content
16,011,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
At the moment I'm using the following to change the file path of a pdf viewer depending on a dropdownlist selection

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default : System.Web.UI.Page
{

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        // Make sure you get a valid file path to a pdf in DropDownList1.SelectedValue
        ShowPdf1.FilePath = "attachments/" + DropDownList1.SelectedValue + ".pdf#toolbar=0&navpanes=0&zoom=50";

    }
   
}


I was wondering if it would be possible to do something like the following:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Default : System.Web.UI.Page
{

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
If "attachments/" + DropDownList1.SelectedValue + ".pdf" exists
then
        ShowPdf1.FilePath = "attachments/" + DropDownList1.SelectedValue + ".pdf#toolbar=0&navpanes=0&zoom=50";

else
ShowPdf1.FilePath = "attachments/NoFile.pdf#toolbar=0&navpanes=0&zoom=50";

    }
   
}
Posted

I think you mean MapPath. That's how you can go from virtual address to file address.

http://msdn.microsoft.com/en-us/library/ms178116.aspx[^]

Good luck!
 
Share this answer
 
Thankyou it put me on the right path to a Solution.

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class Default : System.Web.UI.Page
{

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        string filePath = Request.PhysicalApplicationPath + "attachments/" + DropDownList1.SelectedValue + ".pdf";

        FileInfo imageFile = new FileInfo(filePath);
        bool fileExists = imageFile.Exists;

        if (fileExists == false)
            ShowPdf1.FilePath = "attachments/Nofile.pdf#toolbar=0&navpanes=0&zoom=100";
        else
            ShowPdf1.FilePath = "attachments/" + DropDownList1.SelectedValue + ".pdf#toolbar=0&navpanes=0&zoom=50";
    }
}
 
Share this answer
 
v2

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