Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 31st, 2008, 04:24 PM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default ERROR: Illegal characters in path

hi
i'm trying to load an image from a file to a picture but keep getting the error
Illegal characters in path.
there are two picture boxes on the form
pbFront and pbRear
the lines of code is

pbFront.Image = Image.FromFile(pathF)
pbRear.Image = Image.FromFile(pathR)

when the program runs the
pathF is C:\ArchiveF\Images\20080028\B0031F.bmp
and pathR is C:\ArchiveF\Images\20080028\B0031R.bmp
can somebody tell me what going on here and the files do exists

Owen

Owen, Programmer
Reply With Quote
  #2 (permalink)  
Old April 1st, 2008, 04:49 AM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe there are some non-alphanumeric characters in your paths. Try something like:

pbFrom.Image = Image.FromFile(pathF.Trim())
pbRear.Image = Image.FromFile(pathR.Trim())
Reply With Quote
  #3 (permalink)  
Old April 1st, 2008, 04:59 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Can you show us the lines where you assign pathF and pathR, because there is obviously something wrong with them.

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #4 (permalink)  
Old April 1st, 2008, 07:12 AM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok here is where i assign the paths
ctmpF1 and CtnpF2 are used by the program to get the path to store each file that is scanned.

Public CtmpF1 As New VB6.FixedLengthString(256)
Public CtmpF2 As New VB6.FixedLengthString(256)


CtmpF1.Value = imgpath & "B" & VB.Right("0000" & CStr(Img_count), 4) & "F." & CtmpExt & Chr(0)
CtmpF2.Value = imgpath & "B" & VB.Right("0000" & CStr(Img_count), 4) & "R." & CtmpExt & Chr(0)

pathF = Trim(CtmpF1.Value).Replace(" ", vbNullChar)
pathR = Trim(CtmpF2.Value).Replace(" ", vbNullChar

Owen, Programmer
Reply With Quote
  #5 (permalink)  
Old April 1st, 2008, 09:45 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Why are you using VB6 FixedLengthString? What happens if the imgPath is longer than 250 characters?

Also, why do you have a Chr(0) on the end? What is that for exactly? That will be your invalid character.

Also, I have no idea why you are doing the replace on a space with vbNullChar - this is not valid for a filename either.

Assuming Img_count is an integer then Img_count.ToString("0000") will produce the same result as your VB.Right bit of code as well.

pathF = imgpath & "B" & Img_count.ToString("0000") & "F." & CtmpExt
pathR = imgpath & "B" & Img_count.ToString("0000") & "R." & CtmpExt


/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #6 (permalink)  
Old April 2nd, 2008, 12:57 AM
Authorized User
 
Join Date: Sep 2007
Location: , , Finland.
Posts: 92
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I would suggest that you use String.Format method to build those paths.

Dim pathF As String = String.Format("{0}B{1:0000}F.{2}", imgpath, Img_count, CtmpExt)

If you do many of those inside a loop you could try to use StringBuilder class.

I'm not sure if that formatting is correct :) For some reason I've never got used to .NET's formatting syntax.
Reply With Quote
  #7 (permalink)  
Old April 2nd, 2008, 07:37 AM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi
i stored the path to a string, i could enter the same path in
start >> run in windows and open the image or i could hard code the path into the program and it runs ok.
the problem is when i'm assign the path in the program via a string read from a database or generated within the program

Owen, Programmer
Reply With Quote
  #8 (permalink)  
Old April 2nd, 2008, 08:15 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well this means you're assigning it from the database or 'generating' it incorrectly. But without seeing your code its hard to guess how you might be doing it.

Again some points to look out for:

* avoid all use of both vbNullChar and Chr(0) as these will make a path invalid.
* Don't use VB6.FixedLengthString as it might be truncating your paths if they are longer than 256 character.

Personally I'd recommend using the FolderBrowserDialog control if you are taking path information directly from the user.

/- Sam Judson : Wrox Technical Editor -/
Reply With Quote
  #9 (permalink)  
Old April 2nd, 2008, 10:21 AM
Registered User
 
Join Date: Feb 2008
Location: , , .
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for the tip
the character array was assigning the "Nothing" character value at the end of the string which caused the Error


Owen, Programmer
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Illegal Assignment Broodmdh Classic ASP Basics 2 August 22nd, 2008 06:21 AM
Error while setting class path sujithmathew Linux 1 August 3rd, 2007 01:02 PM
Error: Could not find a part of the path eelisMX Pro VB.NET 2002/2003 2 July 4th, 2006 02:22 AM
Non-english characters gives error ergec Pro PHP 2 February 24th, 2004 09:00 PM



All times are GMT -4. The time now is 10:43 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.