.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Post New Web Links

Feature request for System.IO.Path - GetPublicPath, GetLocalPath

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :.NET Framework

uncPath = System.IO.Path.GetPublicPath( originalPath as string )
localPath = System.IO.Path.GetLocalPath( originalPath as string )

This is constantly a bugger in distributed systems. When saving the full path to a file, say, in a database, one likes to store a public name. Using the most publicly accessible UNC path.  But, to succeed to do so, even if it means using administrative shares (i.e. D$ for D: drive).  In this way, when building distributed systems, components running on remote computers can find the file.  Thus the need for GetPublicPath.

But when you actually go to processing, and you use UNC paths, I have found file access to take longer than when using a purely local path (if possible,... if indeed the file is local). GetLocalPath resolves to simple, non UNC type path names using simple drive letters when possible. But if the file is not local, then it may not change the input path at all. GetLocalPath gives me the most optimal path to the file, given where I am at. Avoiding network elements in the path, when possible.

I have written these for myself, and use them constantly, and am confounded that they don't exist in the framework.

My routines even have the ability to accept a second parameter, which is a computer name, so I can say, calculate a path that would be local, not at the computer I am running from,

View Complete Post

More Related Resource Links

System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPerm


Good Day all,

Having an issue with an outside user accessing my IIS7 box. I do not have this problem when running the website from my host machine. I found this post: Http://forums.asp.net/t/1371394.aspx. I assure you that this is not a solution because I am not storing any of my files on a network share. 

What do you think my approach should be. 

I already have read rights to IIS user to my BIN folder. 

Thanks for the help. 

System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlCli

I have created a windows library control that accesses a local sql database I tried the following strings for connecting Dim connectionString As String = "Data Source=localhost\SQLEXPRESS;Initial Catalog=TimeSheet;Trusted_Connection = true" Dim connectionString As String = "Data Source=localhost\SQLEXPRESS;Initial Catalog=TimeSheet;Integrated Security=SSPI"   I am not running the webpage in a virtual directory but in C:\Inetpub\wwwroot\usercontrol and I have a simple index.html that tries to read from an sql db but throws the error System.Security.SecurityException: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.   at System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet)   at System.Security.PermissionSet.Demand()   at System.Data.Common.DbConnectionOptions.DemandPermission()   at System.Data.SqlClient.SqlConnection.PermissionDemand()   at System.Data.SqlClient.SqlConnectionFactory.PermissionDemand(DbConnection outerConnection)   at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, etc etc  The action that failed was:DemandThe type of the first permission that failed was:System.Data.SqlClient.SqlClientPermissionThe Zone of the assembly that fa

Working with System.IO.Path static class

Hello everyone. Today, I was exploring the System.IO namespace in .NET 4.0 on an ASP.NET web application where I came to few changes, comparing with the previous versions of .NET, related to the System.IO.Path static class. The Path class contains the same method names in .NET 2.0, 3.5 as well as 4.0, only (in .NET 4.0) new overloads are added to System.IO.Path.Combine() method. In the following blog post, I will show the usage of few methods belonging to the System.IO.Path static class, as well as, the changes in Combine() method added in .NET 4.0. Besides the first method that is available in the previous versions for combining two string paths, now in .NET 4.0 you can combine unlimited strings to the path. Note: For testing purpose, on your web application root, create folders with name Files, Files/SubFolder, Files/SubSubFolder and add three text files: text1.txt (in Files), text2.txt (in Files/SubFolder), text3.txt (in Files/SubFolder/SubSubFolder).   Here are few examples:             string path1 = System.IO.Path.Combine(Server.MapPath("Files"), "text1.txt"); //this will give the path to %WEBAPP_ROOT%/Files/text1.text -             string path2 = System.IO.Path.Combine(Server.MapPath("Files"), "SubFolder", "text2.txt"); //this will give

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> Object canno

hello,i am using a web servicewrtitten in .net and i access the webservice from my wepApplication i get this error System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> Object cannot be cast from DBNull to other types.my code is access webservice: protected void btnSave_Click(object sender, EventArgs e)        {            int intStatusCode;            dtProjectStatus = (DataTable)ViewState["dtProjectStatus"];            try            {                objService.Credentials = System.Net.CredentialCache.DefaultCredentials;                if(dtProjectStatus.Rows.Count>0)                {                  intStatusCode = objService.InsertTest(dtProjectStatus);                }   

How is the Path property set in Request.Path?

I have a website which is running on a locally on IIS, and have noticed that I can display an image in /Image/MyImage.jpg from an aspx file in the web root directory with either of the following html:<img src="Image/MyImage.jpg...> or <img src="../Image/MyImage.jpg...>Even though these point to different locations, and <img src="../Image/MyImage.jpg...> is incorrect, they both work and the image is displayed correctly.I've looked into this, and in Application_BeginRequest(), HttpApplication.Context.Current.Request.Path is "/Image/MyImage.jpg" in both cases, which is correct.If I run the website on the local ASP.NET development environment (localhost), it never calls Application_BeginRequest() for the image, and only <img src="Image/MyImage.jpg...> works, which is what I would expect.How is the Request.Path variable set? I find it confusing that two different resource locations would cause the path in Request.Path to point to the same location.

The system cannot find the path specified

I want to run an external command from my c# program and this is how I am running it, but getting the error: "The system cannot find the path specified".Please check my code and debugging details copied below and suggest what I need to fix. Thank You. string MappingCommand = MappingCommandPath + "Mapping.exe /FileName " + HL7FileServerIn + FName;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Process p = Process.Start(MappingCommand);On the debugger I get MappingCommand as: "\\\\csi-myserv-dkv\\DKV\\Projects\\CSIAccessioning\\Altova\\Mapping\\bin\\Debug\\Mapping.exe /FileName C:\\Orders\\ORM2.hl7"    On command prompt when I copy past the above MappingCommand and remove the escape sequences, the following command runs fine.\\csi-myserv-dkv\DKV\Projects\CSIAccessioning\Altova\Mapping\bin\Debug\Mapping.exe /FileName C:\Orders\ORM2.hl7Your help is highly appreciated.

CrystalReportsException: Load report failed - The system cannot find the path specified

I recently added a Crystal Report to a web application within Visual Studio 2010.  I'm using the Push method with a DataSet, and have a CrystalReportViewer control added to an aspx page.  When trying to test the report locally I'm getting an exception when performing the data binding on the CrystalReportViewer control...-----------------------------------------------------------------------------------------------------------------------------------Server Error in '/TestDevelopment' Application. The system cannot find the path specified. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Runtime.InteropServices.COMException: The system cannot find the path specified. Source Error: Line 7: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Line 8: BindReport() Line 9: CrystalReportViewer1.DataBind() Line 10: End Sub Line 11: Source File: C:\Documents and Settings\acwhifield\Desktop\VS_Projects\TestDevelopment\TestDevelopment\a\CR_Rpt_SubSelNotes.aspx.vb Line: 9 Stack Trace: [COMException (0x80004005): The system cannot find the path specified. ] CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(O

System.Net.WebException:an Exception occurred during a Webclient request.

Hi, I have a winforms application where in i want to access the application folder. I am workign on a vista pc. When i try to access the folder, i am getting he folllowing error: System.Net.WebException:an Exception occurred during a Webclient request. ---->System.UnauthorizedaccessException:Accessto the path "C:\ProgramFiles\...\setup.exe" is denied. How can i change this? Is there anyway i can give permissions from within the code? Or is there any other way to resolve this issue? Thanks

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil' in asp.net mvc

I am getting following error in production but the same is not a repro in in local.> Error executing child request for> handler> 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'.> Inner Exception: Exception of type> 'System.Web.HttpUnhandledException'> was thrown.Stack Trace:    at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)    at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage)     at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)    at System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext)         at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)         at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.<InvokeActionResultWithFilters>b__11()    at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)     &

In Reporting Services: Request for the permission of type 'System.Data.SqlClient.SqlClientPermissio

Hello all,In Reporting Services through http://myserver/mydbinstance/Pages/Report.aspx blah de blah blah, I get this error:Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.Actually, the report runs just fine, but some fields had the famous #Error in them. I put some old fashioned debug in my report to TRY, CATCH, END TRY and get the problem to the report so that I could see this report finally run in production. Yes, it runs just fine in VS2005. I have custom code in the report code window that does its own custom connection to an SQL database through "System.Data.SqlClient.SqlConnection" and "System.Data.SqlClient.SqlCommand" to pull in data that is not part of any of the datasources in the report. When I execute the report through the Report Manager or Report site under IIS, the report will run, but I get these errors in every field that uses functions to populate the data.I have searched the web for 3 days now, and the best answers involve using either CASPOL or the Microsoft .NET Framework 2.0 Configuration wizard in Administrative Tools on the server. (I understand that the wizard does the same thing as CASPOL, just through a GUI.) I have followed those steps, but still get the error.I do not know what I need to do to make these DLLs th

Event ID 7000 - The system cannot find the path specified.


This is a very old prolem that i am getting to. First off I went through anywhere from 4 to 6 or more sessions with a Microsoft TECH and it even escalated a couple of levels of TECH support to boot. I can't remember the details specifically. I do know that I've started with gound up (installed/uninstalled NET Framework versions) installs to where I have all the versions installed. The Service doesn't start either automatically nor manual. I tried the patience of the Support people to fix this last error at that time.

I am starting anew to get the NET Framework Service to work properly . I hope I am in the right support forum.


System.ArgumentException: Illegal characters in path



I am trying to download a file from a location and save it in another location using webclient.downloadfile:

This line is erroring out:

myWebClient.DownloadFile(RemoteUri & Files(i), Application.StartupPath & "\" & Files(i))

This is the value in RemoteUri & Files(i):

This is the value in Application.StartupPath & "\" & Files(i):

C:\Program Files (x86)\Microsoft\TestWiform\Testwiform.msi

Error:System.Net.WebException: An exception occurred during a web client request----->System.ArgumentException: Illegal characters in path

What is the illegal character here?

Thanks in Advance


Set Querystring without Page.Request.Path


I do now have the following code for the postback of my dropdownlist.

Response.Redirect(Page.Request.Path.ToString() + "?id=" + (Convert.ToDateTime(ddlDatum.SelectedValue)).ToString("yyyyMMdd"));

Is there another way to do this with the ddlDatum.SelectedValue remembered?

MVC 3 - Feature Request


Been playing with MVC3 and Razor....

I have to say a love the syntax and how clean and readable the view template is with Razor. Looks like I'll actually be using MVC3 in production.

Here is the scenario and I hope we can have a solution for this.

In a layout page I have places where I use Html.RenderAction(). Which basically means I want the content the action renders to be in pretty much every page and the content is quite independent of other views (not their concern). So far so good.

1. What I'd like to do is be able to turn it off while rendering a View, because in certain pages in the system I don't want that content to be shown. I don't see anyway in which I can do that.

2. In some cases, I'd like to be able to control/set the data that is passed on to the Action that RenderAction is calling so that I can control (from the view or controller that is fielding the actual Http request) aspects of the other Action.

xbap Request for the permission of type System.Net.WebPermission failed



I've developed and XBAP application that talks to a WCF service.  I set my XBAP to partial trust and everything worked just fine.

I then added code to the WCF service that uses System.DirectoryServices to talk to my Active Directory server.  I tried to debug the XBAP after I added this code and I am recieving the following error.  Request for the permission of type System.Net.WebPermission failed.

When I set my XBAP to full trust everything works ok.  However I don't understand why I need to set my XBAP to full trust when it's the WCF service that uses System.DirectoryServices to talk with the Active Directory Server and not the XBAP application.


Thanks in advance!

SQL Column Aliases Feature Request


My wish: column alias usage everywhere in the query, not only in the ORDER BY clause.

In the following example you get a syntax error due to column alias usage in the WHERE clause:

USE AdventureWorks2008;

SELECT PC.Name	AS Category, 
  PSC.Name AS Subcategory,
  PM.Name	AS Model, 
  P.Name	AS Product
FROM Production.Product AS P
 FULL JOIN Production.ProductModel AS PM ON PM.ProductModelID = P.ProductModelID
 FULL JOIN Production.ProductSubcategory AS PSC ON PSC.ProductSubcategoryID = P.ProductSubcategoryID
 JOIN Production.ProductCategory AS PC ON PC.ProductCategoryID = PSC.ProductCategoryID
WHERE Category = 'Bike'

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version


I am using Itext sharp to create a pdf. I am adding an image and I keep getting this error

Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

it is this bit of code that is causing this


string imagepath = "C:\\BMSApplicationFiles\\PDFImages\\bullfrogWeb.gif";

//add the Image to the DOC
  Image bullfrogImage = Image.GetInstance(imagepath);
  bullfrogImage.SetAbsolutePosition(10, doc.PageSize.Height - 36);

If i comment this out, the PDF builds and no errors are thrown (there is just no image)

I don't understand cause I am am trying to do is read a file.

The directory does have full permission granted to IISUser

Any ideas why I am still geting this permissions error?

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend