Wrox Programmer Forums
|
.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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2008, 04:24 PM
Registered User
 
Join Date: Feb 2008
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
 
Old April 1st, 2008, 04:49 AM
Authorized User
 
Join Date: Sep 2007
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())
 
Old April 1st, 2008, 04:59 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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 -/
 
Old April 1st, 2008, 07:12 AM
Registered User
 
Join Date: Feb 2008
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
 
Old April 1st, 2008, 09:45 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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 -/
 
Old April 2nd, 2008, 12:57 AM
Authorized User
 
Join Date: Sep 2007
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.
 
Old April 2nd, 2008, 07:37 AM
Registered User
 
Join Date: Feb 2008
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
 
Old April 2nd, 2008, 08:15 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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 -/
 
Old April 2nd, 2008, 10:21 AM
Registered User
 
Join Date: Feb 2008
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.