ASP.net directory on hosting

It is quite a common case to have a website on a remote hosting when, for whatever reason, you can’t afford a full-fledged server onto your fridge or in a remote location. One of the issue you might come across on a hosting server running ASP.net is finding the path of a folder you want to work on. Usually you have a local copy of your website where you work using Visual Studio and then you publish it to the remote location: this is the typical example where the folder structure will not match to the root: you might have a c:\documents\websites\mysite\ that on the hosting server maps as d:\webs\789547\customers\jhondoe\jhondoe.com\. To find the right path both locally, on a hosting location or wherever else there is a simple strategy. Review the following code:

For Each CurrFile As FileInfo In New DirectoryInfo(Hosting.HostingEnvironment.MapPath("\test")).EnumerateFiles
    […
    work on each file
    …]
Next

This piece of code is enumerating all the files in a subfolder called “test” under the root of your website no matter where it is actually located in the absolute directory tree. Review this article on the MSDN library for more information.

Advertisements

Author: lucamauri

First and foremost a geek and a Trekker, Luca Mauri is employed as an IT Manager. A Space Exploration enthusiast, avid reader and hobbyist photographer.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s