Open an Excel File on asp.net

0

I have the following problem:

I want to open an Excel file when I press a button; the file is in a shared folder on a server.

When I'm programming in my localhost , if it works with this code:

protected void BtnChk_Click(object sender, EventArgs e)       
{            
    Process.Start(@"\server\vol1\Files\Book1.xls");
}

That way I click and look for the route, and the excel file starts automatically.

However, when the web application uploads it to the server assigned host and everything, it does not bring me anything.

How can I make it work, or what else could it do? This code is to verify if the file exists, and if it works for me !! I do not understand why visualize it not

            if (File.Exists(@"\server\Files\Book1.xls"))
       {
            ButCrear.Visible = false;
            BtnChk.Visible = true;'

        }
    
asked by CarlosR93 07.03.2017 в 15:46
source

3 answers

1

To give permission to the folder where you have the Excel file to consult, follow these steps:

  • Select the destination folder: Example: C: / myFolder .
  • Press right click > Properties.
  • Go to the Security tab and press the Edit button.
  • A new window will appear. Select the IIS_USRS user and a box with the "IIS_USRS Permissions" will appear below.
  • Select the check in the " Allow / Allow " column to read permission " Read ".
  • Press the " Apply " button and then the " OK " button to save the changes.
  • Try again to access your file.

      

    NOTE: You can give it special permissions or "Full Control", but I do not think it is recommended.

        
    answered by 07.03.2017 в 16:16
    0

    I would recommend that you read a bit of Client Server already if you want to upload your code to a server obviously the process that is going to run is the excel of where your Web application is hosted.

    Now if what you want is that there will be the Excel of the client, then you must use ActiveX, and I regret to say that it only works in IE (I do not know if in others), and the Script Script would be the following.

    function test() {
        var Excel = new ActiveXObject("Excel.Application");
        Excel.Visible = true;
        Excel.Workbooks.Open("teste.xlsx");
      }
    

    Where teste.xlsx is the address of the file (server side). Example. Your folder where your website is:

    link

    Your xlsx file is at the following address:

    link

    then the path would be like this:

    function test() {
        var Excel = new ActiveXObject("Excel.Application");
        Excel.Visible = true;
        Excel.Workbooks.Open("/upload/teste.xlsx");
      }
    

    Greetings.

        
    answered by 07.03.2017 в 19:43
    0

    is because you use the address of the localhost to get the server path from where the page is running use System.Environment.GetEnvironmentVariable and it will show you the folder it is in, I hope it will help you

        
    answered by 17.02.2018 в 15:43