Click here to Skip to main content
15,914,452 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
I have a .msg file already present on the server, which I need to open.
I am using the following code

C#
protected void lnkDelvMail_Click(object sender, EventArgs e)
        {
            string chkViewstate = ViewState["DelvMailPath"].ToString();
            if (chkViewstate == "")
            {
                Response.Write("<script>alert('File Not Uploaded');</script>");
            }
            else
            {
                try
                {
                    var process = new Process();
                    string strFilePath = Server.MapPath(ViewState["DelvMailPath"].ToString());
                    process.StartInfo = new ProcessStartInfo()
                    {
                        UseShellExecute = true,
                        //FileName = dt.Rows[0][16].ToString()
                        FileName = strFilePath

                    };

                    process.Start();
                }
                catch (Exception ex)
                {
                    Response.Write("<script>alert('File cannot be found on the server');</script>");
                }
            }
        }

It opens the file first time properly in outlook but,

when I close the web application and open it again and then try to access the same file
it gives the following error

Cannot open msg file. The file may not exist, you may not have permission to open it, or it may be open in another program.
Right-click the folder that contains the file, and then click Properties to check your permissions for the folder.


Also When I upload the .msg file onto the server and save it there
it is not saved properly. All the contents of the file is blank.

How do i avoid this and open the file every time from my web app.

thanks in advance.
Posted
Updated 27-Jun-13 2:11am
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