server mappath C#

razza_b
razza_b used Ask the Experts™
on
Hi

Does anyone know how to use the server mappath in a silverlight 4 enabled wcf?

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you want to do this in the WCF service ?

Author

Commented:
yes thats where it will be.

Author

Commented:
i need to point to a repo..

"\\SR-SCO-D10\\Labels\\Labels.tfr"
if it's hosted in asp .net web , then something like this should work,

HttpContext.Current.Server.MapPath("~/somefile.txt");

remeber that [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

atribute should be there
Nitesh LuharukaDirector

Commented:
You can return a string from WCF Service similar as HttpContent.Current.Server.MapPath("~/Labels/Labels.tfr") and get the value in SL calling the same service

Author

Commented:
Hi i wont be back online until monday to try examples, niteshl what is your example like?
Nitesh LuharukaDirector

Commented:
Razza,

Did not get your question..

Commented:
Hai ,
       HttpContext.Current.Server.MapPath(".") will give you the current working directory.
HttpContext.Current.Server.MapPath("~/App_Data/sample.tcl");
Or you can use like this also ,
HostingEnvironment.MapPath(".");

You can follow this link also ,
http://msdn.microsoft.com/en-us/library/system.web.hosting.virtualpathprovider.aspx
when you are doing with asp.net you can user mappath function as shown below

HttpContext.Current.Server.MapPath("~/somefile.txt");

other wise you want to do in silverlight and wcf ria services use below syntax,

string filepath = HostingEnvironment.MapPath(filename);
        FileInfo fi = new FileInfo(filenpath);

Author

Commented:
Hi Guys thanks for all your feedback.

i need to use UNC \\ rather than ~ relative path

so if the repo.tfr resides in e.g. 10.148.22.35 server and within the C:\...\...\Labels.tfr directory

could i still get access? and i think i might need to use this if its for silverlight wcf...
form.Repository = HostingEnvironment.MapPath("\\..\..\..\")


Thanks
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
You wouldn't need to use MapPath on a UNC...  A UNC is an absolute path  = )

Author

Commented:
Hi kaufmed in what way would it be used?

Just assign the server path like form.repo = unc server path ??
Glanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015
Commented:
Well the reason you use Server.MapPath is because the ASP process is running under a particular directory (buried in system folders), and your site is in a different directory. When you deal with pages on your site, you typically deal with them in a relative fashion (and sometimes an absolute fashion). However, *this* concept of relative and absolute is with regard to the base directory of the site--not your file system. The base directory of your site is whatever folder you told IIS to look at. Since ASP is running in one directory, and your website is housed in another directory, calling Server.MapPath tells the ASP engine, "locate the folder that I told you my site is housed in, and append this file to that directory path."

Why did I tell you all this? Because you could technically pass the specific path to a file using an absolute filename to whatever construct is expecting a filename. Of couse, if you pass a relative file path, without calling Server.MapPath, then the path is going to be relative to the ASP startup directory, not your site's directory. Since you can pass an absolute filename, and I mentioned that UNCs themselves are absolute filenames, it should just be a matter of passing the filename as a string, without calling Server.MapPath.

e.g.

form.repo = "\\servername_or_ip\share\subfolder";

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial