Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

no application is assosiated with this specified file for this operation

Posted on 2009-04-01
9
Medium Priority
?
763 Views
Last Modified: 2012-05-06
This code  is working fine when i run the application in local mode
However when i access the application using actual url , i am getting the following error
no application is assosiated with this specified file for this operation
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {              
   
        try
        {
           
        
            SelectMaster SelectMaster = new SelectMaster();
            string qry = "select Content_Id,Record_Type,Description from Admn_Course_Organization where Id='" + TreeView1.SelectedNode.Value + "' ";
            DataTable dt_Fill_TV = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry);
            string cid = dt_Fill_TV.Rows[0][0].ToString();
            string recort_type = dt_Fill_TV.Rows[0][1].ToString();
            string desc = dt_Fill_TV.Rows[0][2].ToString();
            if (recort_type.ToString().Equals("OPT"))
            {
                txtdesc.Visible = true;
                txtdesc.Text = desc.ToString();
 
            }              
        
            else
            {
                txtdesc.Visible = false;
                txtdesc.Text = "";
                string qry1 = "select File_Path  from Admn_Content_Mast where Id='" + cid.ToString() + "'";
                DataTable dt_Fill_TV1 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry1);
                string path = dt_Fill_TV1.Rows[0][0].ToString();              
 
            
                string strPath =Server.MapPath("..\\Head_Office_Content") +"\\"+ path.ToString();
 
                txtfile.Text = strPath;            
           
                if (File.Exists(strPath))
                {
                    System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
                    myProcess.EnableRaisingEvents = false;
                    myProcess.StartInfo.FileName = strPath;
                    myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
                    myProcess.Start();
                }
                else
                {
                    string strMsg = "No file to view.";
 
                    Label lbl = new Label();
 
                    lbl.Text = ("<script language=\'javascript\'>"
 
                    + (Environment.NewLine + ("window.alert(" + ("\'"
                    + (strMsg + ("\'" + ")</script>"))))));
                    Page.Controls.Add(lbl);
 
                }
            }
            
 
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
            TreeView1.Visible = false;
        }
 
      
    }

Open in new window

0
Comment
Question by:mannevenu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 16

Expert Comment

by:sunithnair
ID: 24037516
That is because the file is not associated to be opened with any application may be because the file file extension is not registered. I dont understand line 36-40 in your code. I am not sure why you are doing this. If you want the file to be viewed by the user if the file exists then you do will need to write the file to the browser using content-disposition header so that the browser will be able to download the file. Your code will try to run the file on the machine the application is hosted. I am doubtful if it might be of any use.
0
 
LVL 8

Expert Comment

by:Faheem Shaikh
ID: 24037544
0
 

Author Comment

by:mannevenu
ID: 24037815
//This code is for opening any files(like pdf) .but this is not working in Internet.this is working in localhost.
     
                    System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
                    myProcess.EnableRaisingEvents = false;
                    myProcess.StartInfo.FileName = strPath;
                    myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized;
                    myProcess.Start();
         
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 16

Expert Comment

by:sunithnair
ID: 24038247
That is what I said in my first post. You will only be able to use this code if you are browsing from the same machine that hosts the application. This is not useful in the ASP.NET environment. Change your code like this and this should ask you to open/save the file when using on the internet. You might want to change the MIME types. Refer the following links

http://www.w3schools.com/media/media_mimeref.asp
http://kseesharp.blogspot.com/2008/04/c-get-mimetype-from-file-name.html
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {              
        try
        {
            SelectMaster SelectMaster = new SelectMaster();
            string qry = "select Content_Id,Record_Type,Description from Admn_Course_Organization where Id='" + TreeView1.SelectedNode.Value + "' ";
            DataTable dt_Fill_TV = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry);
            string cid = dt_Fill_TV.Rows[0][0].ToString();
            string recort_type = dt_Fill_TV.Rows[0][1].ToString();
            string desc = dt_Fill_TV.Rows[0][2].ToString();
            if (recort_type.ToString().Equals("OPT"))
            {
                txtdesc.Visible = true;
                txtdesc.Text = desc.ToString();
            }              
            else
            {
                txtdesc.Visible = false;
                txtdesc.Text = "";
                string qry1 = "select File_Path  from Admn_Content_Mast where Id='" + cid.ToString() + "'";
                DataTable dt_Fill_TV1 = BusinessLayer.SelectMaster.GetDataTable(Session["ConStr"].ToString(), qry1);
                string path = dt_Fill_TV1.Rows[0][0].ToString();              
 
                string strPath =Server.MapPath("..\\Head_Office_Content") +"\\"+ path.ToString();
                txtfile.Text = strPath;            
                if (File.Exists(strPath))
                {
                    System.IO.FileInfo fi = new System.IO.FileInfo(strPath);
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.ContentType = "application/octet-stream";//Set your MIME Type or refer links provided
                    Response.AddHeader("Content-Disposition", "attachment;filename=" + fi.Name);
                    Response.WriteFile(strPath);
                    Response.Flush();
                    Response.Close();
                }
                else
                {
                    string strMsg = "No file to view.";
                    Label lbl = new Label();
                    lbl.Text = ("<script language=\'javascript\'>"
                    + (Environment.NewLine + ("window.alert(" + ("\'"
                    + (strMsg + ("\'" + ")</script>"))))));
                    Page.Controls.Add(lbl);
                }
            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
            TreeView1.Visible = false;
        }
    }

Open in new window

0
 

Author Comment

by:mannevenu
ID: 24046377
It's working fine.But It asks Open/Save.I want only open the file.But not save option.User not able to save.
0
 
LVL 16

Expert Comment

by:sunithnair
ID: 24047462
Are you just trying to download the PDF file? You can replace the code in lines 28-35 with the following to open pdf files. If you have some other files to be opened like this you will have to set the proper MIME type. The file will be opened inside the browser. Refer links in the above post to get the MIME types.
        System.IO.FileInfo fi = new System.IO.FileInfo(strPath);
        Response.ClearContent();
        Response.ClearHeaders();
        Response.ContentType = "application/pdf";//Set your MIME Type or refer links provided
        Response.WriteFile(strPath);
        Response.Flush();
        Response.Close();

Open in new window

0
 

Author Comment

by:mannevenu
ID: 24047575
The code given by you will open and save the file.But our target is to just view/Read purpose.It should get saved.
0
 
LVL 16

Accepted Solution

by:
sunithnair earned 1500 total points
ID: 24047807
Does it not automatically open the file in the browser? You might have to change some settings in acrobat reader to open files in the broswer. This is the best we can do in a web environment if you want to keep things simple there may be some overly complicated options available just opening the file.
0
 

Author Closing Comment

by:mannevenu
ID: 31565245
thank u sir its help ful
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question