• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 344
  • Last Modified:

Alternative to using Page.Request as a way to get PhysicalApplicationPath

Sample path to folder:

D:\all testing websites go here\test_piratewear\debuglog

Right now my code is using Page.Request (passed in) in order to get the above path.

Is there an alternative to using Page.  Sometimes I can't pass in Page.Request because Request is not available.

Current code:

 public static void SaveOffDebugInfo(HttpRequest hr, string filenameappend)
        {
            string tempGUID = Guid.NewGuid().ToString();

            FileStream fs = null;
                  

            fs = new FileStream(hr.PhysicalApplicationPath + "debuglog\\" + filenameappend + "_" + hr.UserHostAddress + "__" + tempGUID + "_DEBUG.txt", FileMode.Create);

            StreamWriter sw = new StreamWriter(fs);


            foreach (string s in debuglogentry)
            {
                sw.WriteLine(s);
            }


            sw.Flush();

            sw.Close();
        }

Open in new window

0
Tom Knowlton
Asked:
Tom Knowlton
1 Solution
 
Miguel OzSoftware EngineerCommented:
If this path does not change, you can add it to your web config file and read this value every time you need it.
0
 
Tom KnowltonWeb developerAuthor Commented:
The path does change each time.

My eventual solution:

  public static void SaveOffDebugInfo(string filenameappend)
        {
            string tempGUID = Guid.NewGuid().ToString();

            FileStream fs = null;

            string path = HttpRuntime.AppDomainAppPath;

            string ip = HttpContext.Current.Request.UserHostAddress;


            fs = new FileStream(path + "debuglog\\" + filenameappend + "_" + ip + "__" + tempGUID + "_DEBUG.txt", FileMode.Create);

            StreamWriter sw = new StreamWriter(fs);


            foreach (string s in debuglogentry)
            {
                sw.WriteLine(s);
            }


            sw.Flush();

            sw.Close();
        }

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now