none
How to access _Layouts Folder programmatically with the DirectoryInfo Class RRS feed

  • Question

  • Hi,

    i need to cal some files from my Subfolder inside the _layouts Folder through the DirectoryInfo Class. I know that it would be stored be default under c:\program files\common .... but is there any method to get this dynamically? I know how how to use it inside http:// calls. For example: 

    CssRegistration.Register("/_layouts/mysolution/css/style.css")

    But how to do this, when i only want to enumarate the files inside my solution dir (language files) and read them via System.IO Class.

     


    Best regards,
    Yavuz B.

    My Sharepoint Blog http://www.sharepointkb.net
    Wednesday, May 12, 2010 12:43 PM

Answers

  • If your code is going to be running on the SharePoint server (i.e. in a webpart, web control, or a service on the server) then you can use the SPUtility class:

    string sDirectory = Microsoft.SharePoint.Utilities.SPUtility.GetGenericSetupPath("LAYOUTS\YourFolder");
    DirectoryInfo o = new DirectoryInfo(sDirectory);

    Technical Architect at Starznet Ltd. WSS/MOSS development and customisation with a primary focus on CMS.

    Read my wiki at www.intheknow.it for more code and tips for developing with SharePoint 2007 & 2010 Twitter: @starznet
    • Marked as answer by [Yavuz B.] Wednesday, May 12, 2010 1:50 PM
    Wednesday, May 12, 2010 1:17 PM