473,769 Members | 5,601 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
mscorlib.dll

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
either.

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

System.IO.Path. InvalidPathChar s
{Length=0xf}
[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?

Thanks,
Karl Koscher
Nov 16 '05 #1
2 10833
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.

Willy.
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

0
1715
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
10
2190
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? Thanks, alpha
1
5434
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 caused this error. I looked on the newsgroups and noticed that numerous other people were having this...
9
13752
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 user on the local machine.
2
5157
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)
3
15783
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);
1
2334
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 an exception with the message "Illegal characters in path". Please let me know how to achieve the...
9
4016
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
6
4590
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 there some method or property in the IO class that will allow me to CHECK to see if it is safe to...
0
9423
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
jinu1996
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7406
isladogs
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5298
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.