Click here to Skip to main content
15,889,840 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I can able to open the text file when i run the application from local server(with visual studio) but when i try to open the same text file from the hosted site( IIS ), it is not opening(I have created a virtual directory for the same application on IIS.)
C#
string filepath = Server.MapPath(Request.ApplicationPath) + "\\ReleaseNotes\\ReleaseNote.txt";
TextWriter tw = new StreamWriter(filepath);
tw.WriteLine("Text file content");
tw.Close();
ProcessStartInfo pinfo = new ProcessStartInfo();
pinfo.FileName = filepath;
Process p = new Process();
p.StartInfo = pinfo;
p.Start();



Pleas help me out with this issue ....i will appreciate you.
Posted
Updated 10-Sep-13 23:57pm
v4
Comments
[no name] 11-Sep-13 5:16am    
Sure it's opening. It's opening on the server just like you told it to.
Dholakiya Ankit 11-Sep-13 5:24am    
Server.MapPath(Request.ApplicationPath) + "\\ReleaseNotes\\ReleaseNote.txt";
check ur path
argeraju 11-Sep-13 5:56am    
If path is incorrect..how i can able to write the content within that text file....path is correct....the file is not opening....
Dholakiya Ankit 11-Sep-13 6:03am    
argeraju

you have try to open the same text file from the hosted site( IIS ), it is not opening(I have created a virtual directory for the same application on IIS.)

there can be change in path's of local and server you know???????????
argeraju 11-Sep-13 7:11am    
Hello Ankit ,
Thanks for reply..
Please help me out with this issue.So now what should i do for that.
what is the solution for that problem. If you can able to provide solution code i will appreciate you.

C# code is executed at the server, not the client.
It worked in testing, because they were the same machine, so the same folders were available to the client and the server. Now, when you release the code, the server and the client are different PC, perhaps thousands of kilometers apart, and the Server cannot access the Client hard disk at all, for security reasons.

There is no way round this: if the server needs to open the file, it must be transferred from the client to the server first, and then opened - and that has to be done by the client, not the server as it can't access the client HDD at all.

Even if it could, the Process you started would run on the Server, not the Client, so the user would not see it at all - it would start to annoy the heck out of your web host administrator though...
 
Share this answer
 
Comments
argeraju 20-Sep-13 12:56pm    
little bit helped me.
I have solved this issue in another way.After writing the content into text file.I wrote the content of ReleaseNote.txt into the TextFile.aspx page again.This is something as follows within page load event of that page.

    protected void Page_Load(object sender, EventArgs e)
    {


        string filename = "ReleaseNote.txt";

        try
        {
            if (!Page.IsPostBack)
            {
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("content-disposition", "attachment; filename=" + filename);

                FileStream sourceFile = new FileStream(Server.MapPath("~/ReleaseNotes/" + filename), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                long FileSize;
                FileSize = sourceFile.Length;
                if (sourceFile.Length > 0)
                {
                    byte[] getContent = new byte[(int)FileSize];

                    sourceFile.Read(getContent, 0, (int)sourceFile.Length);
                    sourceFile.Close();
                    Response.BinaryWrite(getContent);
                }
                else
                {
                    Response.Write("File is Empty");
                }

                Response.End();
            }
        }
        catch (Exception ex)
        {
            Response.End();
        }



    }

I opened that TextFile.aspx page from code behind of some other page by writing the code something like this:
ClientScript.RegisterStartupScript(typeof(Page), "ErrorOccurred", "<script type='text/javascript'>window.open('ReleaseNotes/TextFile.aspx')</script>");
 
Share this answer
 
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