November Happy Hour will be moved to Thursday December 5th.

Best Practice for getting a directory?

Vote:
 

Hi,

What is considered Best Practice when it comes to getting a CMS5 counterpart for the old /upload/ directory? I've been searching all day and can't really find any good examples of it. Preferably without having to hard code paths in to the code.

Mvh,

/Patrik

#19255
Apr 01, 2008 16:40
Vote:
 

Not sure if it's a best practice, but this works: Smile
1)
Set up a virtual path in your web.config (use the VirtualPathNativeProvider if you have an existing file structure you want to hook up in your solution)
<add showInFileManager="true" virtualName="Photos" virtualPath="~/Photos/" bypassAccessCheck="true" physicalPath="C:\Inetpub\episerverfiles\Photos" name="SitePhotos" type="EPiServer.Web.Hosting.VirtualPathNativeProvider,EPiServer" />

Then, you need to add a <location path="Photos"> section for your new virtual path so that IIS6 can deal with the files.

2)
Now you're good to go, so in your code, you can now get your folder like:
VirtualPathNativeProvider vpnp = (VirtualPathNativeProvider)VirtualPathHandler.GetProvider("SitePhotos"); 

And e.g. return an image url like return vpnp.VirtualPathRoot + "/epiworld.jpg";

 

Not sure if this was what you were looking for, but you can read more about virtualpaths in the sdk.

 --
Lars Øyvind Bodahl
www.epinova.no 

#19309
Apr 03, 2008 8:17
Vote:
 

Hi,

 or like this:

UnifiedDirectory dir = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(virtualPathasString) as UnifiedDirectory;

//Per

#19315
Apr 03, 2008 13:23
Vote:
 

Great, thanks!

Then I'll just add an AppSettings variable so the name of the provider isn't hard coded.

/Patrik 

#19353
Apr 07, 2008 12:58
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.