473,554 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Opening Devices in C# -- Why am I getting "Illegal Characters in Path" exceptions?

I'm trying to communicate with a USB device using C#. I'm able to determine
the device path using P/Invoke and SetupDiGetClass Devs,
SetupDiEnumDevi ceInterfaces, and SetupDiGetDevic eInterfaceDetai l, but I
can't open the device using File.Open. I get the following error:

An unhandled exception of type 'System.Argumen tException' occurred in

Additional information: Illegal characters in path.

The path name is
\\?\usb#vid_0da 0&pid_1000#6&2d 560690&0&1#{6d2 f6bb8-73e9-4283-a478-b6b493962df9}

The path name is determined by code, so it shouldn't be a problem with not
properly escaping the slashes. Even double- and triple-escaping the slashes
doesn't do any good. There aren't any hidden null characters in the string

Dumping System.IO.Path. InvalidChars produces: (non-printable chars removed)

System.IO.Path. InvalidPathChar s
[0x0]: 0x22 '"'
[0x1]: 0x3c '<'
[0x2]: 0x3e '>'
[0x3]: 0x7c '|'
[0x4]: 0x0 ''
[0x5]: 0x8
[0x6]: 0x10
[0x7]: 0x11
[0x8]: 0x12
[0x9]: 0x14
[0xa]: 0x15
[0xb]: 0x16
[0xc]: 0x17
[0xd]: 0x18

Any ideas why .net doesn't like this? Looking at the stack trace, my hunch
is that it's trying to split the file name into the directory and file name
parts, and \\?\ isn't a "real" directory. Is there a way to open this device
without resorting to using P/Invoke and CreateFile/ReadFile/WriteFile?

Karl Koscher
Nov 16 '05 #1
2 10821
Is there a way to open this device
without resorting to using P/Invoke and CreateFile/ReadFile/WriteFile?

No, the FCL are designed to open logical files only. So you will have to
PInvoke CreateFile and use the file handle returned to access the device
using the FileStream class.

Nov 16 '05 #2
> No, the FCL are designed to open logical files only. So you will have to
PInvoke CreateFile and use the file handle returned to access the device
using the FileStream class.

Thanks! I wasn't aware that FileStream could use native file handles. It
works fine now.

- Karl
Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: BenO | last post by:
Hi I'm new to python and need to write a function to replace certain characters in a string (html). The characters I need to replace come from MS Word copy & paste and are: ' (Left quote) ' (Right quote) Double Left quotes
by: Alpha | last post by:
I use FolderBrowserDlg for user to select a folder path then store it in the sql table. I then retrieve it to concatenate in a sqlcommand text to retrive files from that directory but it won't work because the database has it as "\\Support\VMS\VMSDB" while the C# code expects to see @"\\Support\\VMS\\VMSDB" . Is there a way to fix this? ...
by: Steve Grahovac | last post by:
I have been having trouble the last few days opening any ASP.NET web forms in the design view in the designer. Every time I clicked on an aspx file I got a message box with the error "Unable to open in designer. Illegal characters in path" and the file is instead opened in HTML view. I don't know what application or situation may have...
by: Clinton Frankland | last post by:
Hi, On a Windows 2000 Server when attempting to use System.IO.Directory.CreateDirectory(string.concat(Server.MapPath(""), "\verify")) I receive a System.IO.DirectoryNotFoundException error: Could not find a part of the path "D:\". The full path is "D:\hshome\clinton\test.gotchasoft.com\verify" The web is running using impersonation as a...
by: Guoqi Zheng | last post by:
Dear sir, I am trying to save a binary data by below script, however,it always give me an error of "Could not find a part of the path "C:\temp\". " Any idea what I did wrong here? Public Sub SaveAs(ByVal strPath As String)
by: Eckhard Schwabe | last post by:
I only found one post on Google where someone mentions the same problem with a DataSet: XmlDataReader in .Net 1.1 can not read XML files from a path which contains "%10" or "%3f". code to reproduce: string filename = "%10.xml"; //XML file with this name is existing XmlReader reader = new XmlTextReader(filename);
by: Shilpa | last post by:
Hi, I have a OpenFileDialog on my windows form whose filter is *.*. I want the users to be able to further filter the files by giving *.doc or *.zip etc in the "file name" field of the dialog (Just like it happens in the open file dialog of MS Word) Currently, if the user enters a wild card character in the file name field, it is throwing...
by: larrybud2002 | last post by:
I've read about this error in this group and others from early 2006 but without any resolution, so I thought I'd bump it up to see if there's a solution. Trying to build a website on http://oursite:8080/ and it returns
by: =?Utf-8?B?UGF1bA==?= | last post by:
I am getting an "Access to the path "xxxx" is denied error. I believe is because the file that I am writing to programatically is being read/written to by another end user. These files have the same file name and must have the same file name. I am essentially overwrite an existing file that is being used by another user. My question: Is...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.