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

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Handling ArgumentException: Illegal characters in path

Posted By:      Posted Date: September 16, 2010    Points: 0   Category :ASP.Net
How can I handle URLs with illegal characters such that they don't throw an unhandled exception? I tried an HttpModule but that doesn't catch the error. I'm using IIS6 and .Net 2.0.

View Complete Post

More Related Resource Links

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


Deployment Failure - System.ArgumentException: Illegal characters in path.


I have created an asp.net MVC3 website I would like to upload via Webmatrix. The website uses a database I set up in webmatrix (SQL Compact Databases). I am using an ado.net data entity model to interface with the database. The website runs properly on my local machine, but when I attempt to deploy it via webmatrix I recieve the following error:

System.ArgumentException: Illegal characters in path.
   at System.IO.Path.CheckInvalidPathChars(String path)
   at System.IO.Path.IsPathRooted(String path)
   at Microsoft.WebMatrix.Deployment.DeployFilesFilter.ApplyFilterForSqlCeInternal()
   at Microsoft.WebMatrix.Deployment.DeployFilesFilter.ApplyFilterForSqlCe()
   at Microsoft.WebMatrix.Deployment.DeployFilesFilter.ApplyFilters()
   at Microsoft.WebMatrix.Deployment.MsDeployWorker.Execute(Boolean pullback)

 After a little experimentation I have determined that ths problem appears to be linked to my web.config connection string for the databases (With this string removed the deploy error no longer occurs).

<add name="MyDatabaseEntities" connectionString="metadata=res://*/Models.MyDatabaseModel.csdl|res://*/Models.MyDatabaseModel.ssdl|res://*/Models.MyDatabaseModel.msl;provider=System.Dat

Illegal characters in path

I have a web site developed in ASP.NET 2.0 and VB.Net.It works perfectly on my PC when I launch it from visual studio but when i copy it on server it shows an error: Illegal characters in path. 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.ArgumentException: Illegal characters in path.Where is the problem??

SQL Server 2008 enterprise upgrade failed: Illegal characters in path.


My production upgrade from SQL Server 2005 to 2008 just went down. This is a single x64 server installation the log reported the strange set of problems:


2011-04-13 10:14:48 AS: Result: (Utility) Success
2011-04-13 10:14:48 AS: Action: Set Admin Rights For Folder(F:\SSAS\AS_TEMP\|)
2011-04-13 10:14:48 Slp: Sco: Attempting to set directory full path
2011-04-13 10:14:48 Slp: Sco: Attempting to normalize directory path F:\SSAS\AS_TEMP\|
2011-04-13 10:14:48 Slp: Prompting user if they want to retry this action due to the following failure:
2011-04-13 10:14:48 Slp: ----------------------------------------
2011-04-13 10:14:48 Slp: The following is an exception stack listing the exceptions in outermost to innermost order
2011-04-13 10:14:48 Slp: Inner exceptions are being indented
2011-04-13 10:14:48 Slp: 
2011-04-13 10:14:48 Slp: Exception type: Microsoft.SqlServer.Configuration.Sco.ScoException
2011-04-13 10:14:48 Slp:   Message: 
2011-04-13 10:14:48 Slp:     Illegal characters in path.
2011-04-13 10:14:48 Slp:   Data: 
2011-04-13 10:14:48 Slp:    DisableRetry = true
2011-04-13 10:14:48 Slp:   Inner exc

Problem Cleaning Illegal Characters out of an XML String



I'm trying to strip illegal characters out of an XML string before I send it off to a public web service.  The xml will look something like this:

<field name="first_name">George</field>
<field name="last_name">Harrison</field>
<field name="notes">This is a note.  Any character could appear here</field>

I need to pull out any ampercand (&) charachters in the any of the fields, as well as any < or > characters, which would make the XML unreadable.

I've tried it like this:

Private Shared Function cleanQuery(ByVal queryNode As String) As String 
    Dim root As XElement = XElement.Parse(queryNode) 
    For Each x As XElement In root.Elements 
        x.Value = x.Value.Replace("&", "&").Replace("<", "<").Replace(">", ">") 
    Return root.ToString() 
End Function


That doesn't work so well.  I get the error stating:

     There are multiple root elements. Line 1, position 15.

I tried wrapping the XML in a single root element, like this:

Private Shared Function cleanQuery2(ByVal q

260 Characters in File Path - Too long


I have a Windows Service that is getting cought up on file paths that are longer than 260 characters.  I have googled just about every combination of this problem I can think of as well as various other forums.  From what I have read, Windows System.IO has a limitation on file paths of 260 characters or less.  However Microsoft's latest release of Robocopy has support for 260+ characters.  I have also read that a couple people mentioned unicode file paths which support up to 32,000.  The limitation is set with the MAX_PATH and internet explorer and Robocopy use unicode filepaths to save long files.

My workaround right now is to trap and skip the folders while I would like in the future to be able to have paths longer than 260 characters.  This right now is the ONLY work around, so the obvious "why dont you just move the folders?" response is out of the question.

My question is: Is there a way to use unicode file paths with the FileInfo class?  Perhaps using PInvoke?  Can you give an example for me?

Event Type: Error
Event Source: File Mirroring Service
Event Category: None
Event ID: 0
Date:  8/9/2005
Time:  8:42:28 AM
User:  N/A
An error occured:
The path is too long after being

Sharepoint/SSRS: The full path must be less than 260 characters long

Question: I setup a dual server Sharepoint deployment with SSRS and now I keep getting the error like the one below when I try to save a report or a datasource on the server:

The path of the item 'http://intranet/sharepoint/CompanyReports/MyReports' is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash.

I'm looking into permissions but this happens regardless of authentication I select on the client end.


Every self-respected programmer should include exception handling techniques. Sometimes your application will generate an error. Regardless of who was responsible for this error, the programmer or the user, it is up to the first to include the necessary exception handling techniques to keep his/her program from crashing. The .Net environment provides useful techniques for avoiding disastrous errors such as try-catch statements and user-defined exceptions.

Global Exception Handling with ASP.NET

After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

SQL Server 2005 Try and Catch Exception Handling

I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

Virtual Path Problem


 I get the following error on last line below (working on remote host): 'E:\web\sfcascom\ls_admin/uploads/images/001.JPG' is not a valid virtual path,

Note that the slashes go in different directions

I've tried a number of things but nothing seems to work. Thanks-


Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Drawing.Imaging
Imports System.Web.UI.WebControls

Imports System.Drawing.Imaging.ImageCodecInfo
Partial Class Protected_imageupload
    Inherits System.Web.UI.Page
    Private Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
        ' Initialize variables
        Dim sSavePath As String
        Dim sThumbExtension As String
        Dim intThumbWidth As Integer
        Dim intThumbHeight As Integer
        Dim sFilename As String = ""
        ' Set constant values
        'sSavePath = "images/"
        sSavePath = Server.MapPath("~/") + "ls_admin/uploads/images/"

        sThumbExtension = "_thumb"
        intThumbWidth = 160
        intThumbHeight = 120

        ' If file field isn?t empty
        If FilUpload.PostedFile IsNot Nothing Then
            ' Check file size (mustn?t be 0)
            Dim myFile As Http

Handling 404 page not found with Error page



      How do i handle 404 page not found?

Creating a user friendly alias for the website path


 Hello mates,

I am hosting my ASP.NET application on a Windows 2003 Server.

To browse to my application one has to type the path :http://serverName/applicationName

I want users to only type  applicationName on the web adress area.I believe there is something to do with alias and CNAME on DNS records that can adress this.

Any help on how to go about doing this will be highly appreciated.

Error while using exception handling block el 4.1


Hi Folks,


i am trying to use tyhe exception handling block of Enterprise library 4.1.


I just createda polisy and used IndexOutOfRangeException and added a replace handler and a logging handler to it.

I am using the NotifyRethrow PostHandlingAction to the exception.


During runtime I am getting an exception on the HandleException event, The exception is added below:



Object reference not set to an instance of an object.

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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 42:             catch (Exception ex)
Line 43:             {
Line 44:                 bool reThrow = ExceptionPolicy.HandleException(ex, "ReplacePolicy");
Line 45:         

How to set SearchRoot Path in Active Directory in this scenario


How to set SearchRoot Path in Active Directory in this scenario:

Functionality: We have scenario that 1<sup>st</sup> hit one LDAP server with some 'fixed user name' &' fixed password ' and filter data with specific User name(which given by user) getting 'User dn'.

After that we hit Next LDAP server based on the 'User dn' getting from 1<sup>st</sup> server.

(So, in my case 1<sup>st</sup> LDAP server works like as Load balancing server but functionalitywise it is different)


IE 8 Issues with Chinese/Japanese Characters


On my web application, I display information in different languages. Everything works fine in IE compatibility mode and FireFox but it shows boxes for chinese/japanese languages. I am pretty much having the same issue as described here



Thanks for your help.

Store and display Japanese characters



Can anyone tell me the best way of storing Japanese characters through ASP.NET.
I have to put characters into a asp:textbox on one page, which saves it to an Access DB.
On a second page I want to display the content in a asp:label.

Should I store the characters directly to the database or should they be encoded, and
how do I encode the characters? 

In my web.config i have:

<globalization fileEncoding="ISO-2022-JP" requestEncoding="ISO-2022-JP" responseEncoding="ISO-2022-JP" culture="ja-JP" uiCulture="ja-JP" />  

On the display page I have:

<meta HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=shift_jis">


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