"The Given Path's Format Is Not Supported."

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.

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

error:The given path's format is not supported

I don't know what culture your machine is set to but I assume calling DateTime.Now.ToString() gives you something like 08/02/2017 11:41:30 which contains slashes and colons and is therefore not a valid path.

Try specifying a format inside ToString() like this:

ss.SaveAsFile(projectPath+"Screenshots\\Drisha"+DateTime.Now.ToString("ddMMyyyyHHmmss")+".jpeg", ImageFormat.Jpeg); 

As a side note you should not be concatenating strings to make a path, instead use Path.Combine.

ss.SaveAsFile(Path.Combine(projectPath, "Screenshots\\Drisha", DateTime.Now.ToString("ddMMyyyyHHmmss"), ".jpeg"), ImageFormat.Jpeg);

“The given path's format is not supported.”

Change this:

string filePath = @"\\G:\SharedDrive\Forms\FormOne\" + filename;

To this:

string filePath = @"G:\SharedDrive\Forms\FormOne\" + filename;

Or if it is a network share, then something like this:

string filePath = @"\\SharedDrive\Forms\FormOne\" + filename;

where "SharedDrive" is the name of the network share.

(edited in response to first comment below)

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 in vb.net

Your are passing the result of (BoldOn + ("C:\vDos\#LPT1.asc" + BoldOff)) to the szFileName parameter of your method but the one and only place that parameter is being used is here:

Using fs As New FileStream(szFileName, FileMode.Open)

The prefix and suffix you're adding are creating a value that is not a valid file path as far as the FileStream constructor is concerned, hence the exception. You need to pass a valid file path to that constructor.

It appears that that prefix and suffix are supposed to be passed to the printer somehow, but you're not doing that. My guess would be that you need to add that prefix and suffix to the actual data from the file, not the file path, e.g.

Dim BoldOn As Byte() = Encoding.UTF8.GetBytes(ESC + ("E" + "\u0001"))
Dim BoldOff As Byte() = Encoding.UTF8.GetBytes(ESC + ("E" + "\0"))

Dim fileContents = File.ReadAllBytes(filePath)
Dim dataToPrint = BoldOn.Concat(fileContents).Concat(BoldOff).ToArray()

It appears that I need spell it out in detail, so here's your original code modified to incorporate what I explained above:

Private Shared ESC As String = "\u001B"
Private Shared BoldOn As Byte() = Encoding.UTF8.GetBytes(ESC + ("E" + "\u0001"))
Private Shared BoldOff As Byte() = Encoding.UTF8.GetBytes(ESC + ("E" + "\0"))

Public Shared Function SendFileToPrinter(printerName As String, filePath As String) As Boolean
Dim bytes = BoldOn.Concat(File.ReadAllBytes(filePath)).Concat(BoldOff).ToArray()
Dim byteCount = bytes.Length
Dim unmanagedBytesPointer = Marshal.AllocCoTaskMem(byteCount)

Marshal.Copy(bytes, 0, unmanagedBytesPointer, byteCount)

Dim success = SendBytesToPrinter(printerName, unmanagedBytesPointer, byteCount)

Marshal.FreeCoTaskMem(unmanagedBytesPointer)

Return success
End Function

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim printer = "Generic / Text Only"

SendFileToPrinter(printer, "C:\vDos\#LPT1.asc")
End Sub

Note that it is just an educated guess that you need to combine those printer commands with the file contents. It's up to you to confirm that and, if it's not the case, find out what is required.

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


Related Topics



Leave a reply



Submit