The given path's format is not supported.
Rather than using str_uploadpath + fileName
, try using System.IO.Path.Combine
instead:
Path.Combine(str_uploadpath, fileName);
which returns a string.
What is causing NotSupportedException (The given path's format is not supported) while using a valid path?
According to the reference source: http://referencesource.microsoft.com/#mscorlib/system/io/filestream.cs#732
NotSupportedException
will be thrown if the index of the :
in your path is at the third position or later. (One would expect :
to be the second character) Are you sure there are no zero-width combining characters or other similar Unicode shenanigans going on in your source?
the given path's format is not supported. c#
Here you use the correct way of formatting the path in Windows with a Backslash
ofd.InitialDirectory = @"C:\Picture";
And in the next line you divert from it
System.IO.File.Copy(ofd.FileName, "/Resources/SImages/" + lblRNo.Text + ".jpg");
just keep the way you did it in the beginning:
System.IO.File.Copy(ofd.FileName, @"\Resources\SImages\" + lblRNo.Text + ".jpg");
One way of avoiding such irritations is to use System.IO.Path.Combine()
string path = System.IO.Path.Combine("Resources", "SImages");
EDIT: due to the extraordinary observation by Steve I changed lblRNo
to lblRNo.Text
The given path's format is not supported (listing files)
Use the the common -ErrorVariable
(-ev
) parameter parameter in combination with the common -ErrorAction
(-ea
) parameter:
Get-ChildItem $myPath -Recurse -Force -File -ea SilentlyContinue -ev errs |
Where-Object {$_.name -match '[?<>|/\\*:"]+'} | select fullname, name
Write-Verbose -vb 'The following paths caused errors:'
$errs.TargetObject
-ea SilentlyContinue
silences error display (and continues execution as long as the errors are non-terminating, which they typically are).-ev errs
captures the non-terminating errors in self-chosen variable$errs
, which can be inspected later.
The .TargetObject
property of the System.Management.Automation.ErrorRecord
instances collected in $errs
contains the source object that triggered the error, which in the case at hand is the full path of the file-system object; $errs.TargetObject
lists them all, across all error objects in the collection, courtesy of member-access enumeration.
Update:
The above doesn't seem to help in the specific case at hand, as seemingly only a single error record is returned that doesn't have
.TargetObject
filled in and mentions only the starting directory of the recursive enumeration.The
Include *
approach shown below helped to at least narrow the problem down to individual directories containing offending files.
Adding -Include *
to force explicit processing of individual files in each directory may help:
# Tries to find offending file names only, via `$errs`
$null = Get-ChildItem $myPath -Recurse -Force -File -Include * -ea SilentlyContinue -ev errs
Another option, given that you say that passing -Directory
doesn't report errors, is to apply Get-Item * -Force
to each directory and see if the offending file names can at least be narrowed down to specific directories:
# Tries to find offending file names only, via `$errs`
$null = & { Get-Item $myPath; Get-ChildItem $myPath -Recurse -Force -Directory } |
Get-Item -Path { Join-Path $_.FullName * } -Force -ea SilentlyContinue -ev errs
Why I am getting The given path's format is not supported error
I tried this on another computer but still it didn't work!(Surprising).
I have managed to solve this issue by moving "file.txt" to my project folder.
Now I am using
string oldfilename = "file.txt";
string newfilename = "tree.txt";
System.IO.File.Move(oldfilename, newfilename);
And this Works!
This doesn't seems to be an answer to this question(for me), but It has really worked for me.
Why i'm getting NotSupportedException: The given path's format is not supported?
Your usage of DateTime
results in illegal characters for a directory name, as an alternative you can use DateTime.Now.ToFileTime()
which is a number representation of the current time (not necessarily unique if you do this concurrently or in a loop).
Strings not working in my function as parameters powershell
You are not correctly calling your function. You use a function as such:
cee 'C:\FAKE' 'C:\zipfile.zip'
Or more fully, by calling parameters by name:
cee -a 'C:\FAKE' -b 'C:\zipfile.zip'
Related Topics
How to Get a Uri of the Image Stored in the Resources
Difference Between "Var" and "Object" in C#
Example Using Hyperlink in Wpf
Linq Expression to Return Property Value
How to Make a Hyperlink Work in a Richtextbox
Webbrowser Documentcompleted Event Fired More Than Once
How Does Static Field Initialization Work in C#
How to Bind Crystal Report to Manually Created Dataset
Should I Store My Images in the Database or Folders
What Is the Point of Lookup<Tkey, Telement>
Getting Checkbox Value in ASP.NET MVC 4
How to Find Out If a File Exists in C#/.Net
How to Get the Closest Number from a List<Int> with Linq