Search code examples
sharepointincluderesponse.write

Include file in Sharepoint


I have an include file "menu.inc" that I would like to store in the Style Library folder.

Is there a way to include this file in my masterpage from inside Sharepoint? Response.Write doesn't seem to work because it requires a physical path.

Any ideas?


Solution

  • I solved the issue using the following code:

    string htmlUri = SPContext.Current.Site.RootWeb.Url.ToString() + "/Style%20Library/menu/menu.inc";
    
    WebRequest req = WebRequest.Create(htmlUri);
    req.UseDefaultCredentials = true;
    req.PreAuthenticate = true;
    req.Credentials = CredentialCache.DefaultNetworkCredentials;
    
    WebResponse responseHtml = req.GetResponse();
    
    using (StreamReader r = new StreamReader(responseHtml.GetResponseStream()))
    {
        tdMenu.InnerHtml = r.ReadToEnd();
    }
    

    Thanks everyone!