Process.Start no funciona después de alojar la aplicación web asp.net en IIS

I have a return a c# code to save a file in the server folder and to retrieve the saved file from the location. But this code is working fine in local machine. But after hosting the application in IIS, I can save the file in the desired location. But I can't retrieve the file from that location using

Process.Start

What would be the problem? I have searched in google and i came to know it may be due to access rights. But I don't know what would be exact problem and how to solve this? Any one please help me about how to solve this problem?

To Save the file:

string hfBrowsePath = fuplGridDocs.PostedFile.FileName;
if (hfBrowsePath != string.Empty)
{
    string destfile = string.Empty;
    string FilePath = ConfigurationManager.AppSettings.Get("SharedPath") + ConfigurationManager.AppSettings.Get("PODocPath") + PONumber + "\\\\";
    if (!Directory.Exists(FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1)))
       Directory.CreateDirectory(FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1));
    FileInfo FP = new FileInfo(hfBrowsePath);

    if (hfFileNameAutoGen.Value != string.Empty)
    {
        string[] folderfiles = Directory.GetFiles(FilePath);
        foreach (string fi in folderfiles)
        File.Delete(fi);
        //File.Delete(FilePath + hfFileNameAutoGen.Value);
    }
    hfFileNameAutoGen.Value = PONumber + FP.Extension;
    destfile = FilePath + hfFileNameAutoGen.Value;
    //File.Copy(hfBrowsePath, destfile, true);
    fuplGridDocs.PostedFile.SaveAs(destfile);
}

To retrieve the file:

String filename = lnkFileName.Text;
string FilePath = ConfigurationManager.AppSettings.Get("SharedPath") + ConfigurationManager.AppSettings.Get("PODocPath") + PONumber + "\\";
FileInfo fileToDownload = new FileInfo(FilePath + "\\" + filename);
if (fileToDownload.Exists)
     Process.Start(fileToDownload.FullName);

preguntado el 01 de febrero de 12 a las 04:02

What does "not working" mean? What happens instead? -

How are you saving a file in the server folder and retrieving the saved file from the location, provide code. And what are you doing in Process.Start -

log error info, paste here; perhaps you're having partial trust issues on shared hosting. -

Hi, I have added the code to save and retrieve the file. Please check my question again. -

Sugerencia: use Path.Combine to create a file or folder path -

2 Respuestas

It looks like folder security issue. The folder in which you are storing the files, Usuari@s group must have modificar access. Basically there is user(not sure but it is IIS_WPG) under which IIS Process run, that user belongs to Usuari@s group, this user must have modificar access on the folder where you are doing read writes.

Sugerencias

  • Utilizan Path.Combine to create folder or file path.
  • Puede usar el String.Format to create strings.
  • Create local variables if you have same expression repeating itself like FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1)

Espero que esto funcione para usted.

Respondido 01 Feb 12, 09:02

I can create the file. But the only problem is I cant view the saved file. where i can find the IIS_WPG user and how to give modify permission? - la furgoneta

If you can save file, then it's not security issue. Can you check if you are saving and retrieving same file? You can also try throwing error if (fileToDownload.Exists) fails. And what is PONumber, you are saving file with that name and retrieving using lnkFileName.Text - Amar Palsapure

actually PONumber is an autogenerated one. The selected file will save in the folder as PONumber + its extension. For ex: Notepad file would be saved in the folder as 'PO-11-009.txt'. So after saving the file, the file name 'PO-11-009.txt' would be assigned as the text to the LinkButton. So I can retrieve the filename by getting the LinkButton Text. - la furgoneta

En ese caso tu Process.Start will try to launch .txt file, and it will try to open default editor for this, most probably it will be notepad. But don't think IIS has access to launch Notepad, need to check. What are you trying to achieve with Process.Start? - Amar Palsapure

Process.Start(filenamewithfullpath); In that I give the full path of the file to open. By using this, I just want to open the file in the path. - la furgoneta

You may have to give permissions to the application pool that you are running. see this link http://learn.iis.net/page.aspx/624/application-pool-identities/

You can also use one of the built-in account's "LocalSystem" as application pool identity but it has some security issue's.

Respondido 01 Feb 12, 09:02

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.