Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1020175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:07:33+00:00 2026-05-16T11:07:33+00:00

I want to ask how to open a specific file (the file is out

  • 0

I want to ask how to open a specific file (the file is out of the server, i have a relative path to it stored in config file) with its application, when clicking on a specific link button or hyper link…

like :

opening

.docx with word.

or

.pdf with acrobat reader

i tried several methods but , i get different errors like

Cannot use a leading .. to exit above the top directory

my .cs:

public void ProcessRequest(HttpContext context)
        {
            
                int newsId = int.Parse(context.Session["newsId"].ToString());
                int FK_UnitId = int.Parse(context.Session["UserData"].ToString());
                string dirPathForTextFiles = ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsTextFiles" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId + "/";
                DataTable UpdatedDateTable = (DataTable)context.Session["theLastUpdatedTextFile"];
                UpdatedDateTable.AcceptChanges();
                context.Session.Add("currentTextFile", UpdatedDateTable);
                List<string> l = new List<string>(UpdatedDateTable.Rows.Count);
 
                try
                {

                    l.Add(dirPathForTextFiles + UpdatedDateTable.Rows[0]["fileName"].ToString());
                    context.Response.ContentType = getContentType(dirPathForTextFiles + UpdatedDateTable.Rows[0]["fileName"].ToString());
                    System.Diagnostics.Process.Start(l[0]);         
                    context.ClearError();

                }
                catch (IOException e)
                {
                    string message = e.Message;
                }

            
        }

        string getContentType(String path)
        {
            switch (Path.GetExtension(path))
            {
                case ".doc": return "   application/msword";
                case ".docx": return "application/msword";
                case ".pdf": return "application/pdf";
               
                default: break;
            }
            return "";
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:07:34+00:00Added an answer on May 16, 2026 at 11:07 am

    In order to get the full file path on the server you’ll want to use Server.MapPath.

    string fullFileName = Server.MapPath("../myFile.pdf");
    

    Edit: After that you’ll need the Process object to “run” it:

    System.Diagnostics.Process.Start(fullFileName);
    

    Edit 2: If you want the file to be opened on the client side, your best bet is to create and HTTP Handler and set the appropriate mime type on your response before streaming it out from your handler.

    Edit 3: Code to stream a file out to client.

    public void ProcessRequest(HttpContext context)  
    {   
       int newsId = int.Parse(context.Session["newsId"].ToString());
       int FK_UnitId = int.Parse(context.Session["UserData"].ToString());
       string dirPathForTextFiles =  ConfigurationManager.AppSettings.GetValues("ThePath").First() + "/" + "NewsTextFiles" + "/" + "UnitNum" + FK_UnitId.ToString() + "_" + "NewsNum" + newsId + "/";
       DataTable UpdatedDateTable = (DataTable)context.Session["theLastUpdatedTextFile"];
       UpdatedDateTable.AcceptChanges();
       context.Session.Add("currentTextFile", UpdatedDateTable);
       List<string> l = new List<string>(UpdatedDateTable.Rows.Count);
    
       try
       {
    
          l.Add(dirPathForTextFiles + UpdatedDateTable.Rows[0]["fileName"].ToString());
           context.Response.ContentType = getContentType(dirPathForTextFiles + UpdatedDateTable.Rows[0]["fileName"].ToString());
           using (FileStream fs = new FileStream(l[0], FileMode.Open, FileAccess.Read))
           {
              long chunkSize = fs.Length; 
              byte[] buf = new byte[chunkSize]; 
              int bytesRead = 1; 
              bytesRead = fs.Read(buf, 0,(int)chunkSize); 
              if (bytesRead > 0) context.Response.OutputStream.Write(buf, 0, buf.Length);
              context.Response.OutputStream.Flush();
          }
    
      }
      catch (IOException e)
      {
         string message = e.Message;
      }   
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to ask some questions about the JSP and JSON file. I have
I have a file with the top 1000 baby names. I want to ask
I want to ask that in c programming we open a file using pointer
I want to ask you something. I make the application web with the Google
I want to ask pro developers out there that how they manage a big
I want to ask that If have read that it is possible to give
Hello ever one I want to ask a question about file opening.I want to
Hello every one I want to ask a question about file transfer using sockets.
I want to ask that , can I open iPhone camera in some limited
I know how to implment a Simple comet server。 but I want to ask:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.