picture.fromData UnsupportedFormatException

Trying to convert a string to a picture and have run into a problem.

Pictures are stored in a database in what look like two different formats.
One works with the following instruction;
p=picture.FromData(DecodeBase64(data))

And one works with:
p = Picture.FromData(data)

If the incorrect instruction is used I get a "UnsupportedFormatException

Is there a way to select something is the string to know which to use?

Or is there some way to use “Try”?

this should work

dim p2 as string=decodebase64(data)
if len(p2)<>0 then 
  p=picturefromdata(p2)
else
p=picturefromdata(data)
end if

Nope.

P2 is always > 0.

Still get exception on one type.

interesting… my testing showed that if the string was not a valid base64 that decode returned a 0 length string

Did you try Try? :slight_smile:

Untested but something like

[code]dim p As Picture
Try
p = Picture.FromData(data)
Catch exc As UnsupportedFormatException
Try
p = Picture.FromData(DecodeBase64(data))
Catch exc As UnsupportedFormatException
//handle couldn’t load here??
End Try
End Try

if p = nil then
Msgbox “couldn’t load”
else
//p is loaded
end[/code]

Will, had to change above line to “exc1” and add “Return p”, other wise it works mostly.

There is one problem if first “Fromdata” fail and the second “Fromdata” also fail it drops into the ExceptionHandler, Is there a way to prevent that?

I really appreciate you guys help.

Now let me say why, I think, both “FromData” fails. The files was an “Alias”. I need to not except an “Alias”.

an alias is not a picture … but an alias !

If the alias is valid, it should resolve automatically to the target folderItem.

[quote=286903:@Michel Bujardet]

If the alias is valid, it should resolve automatically to the target folderItem.[/quote]
Yes but in this case the original file was missing. without any indication that was so.

But at that point the folderItem.Exists should be false, or the folderItem be nil, so you can spot it.

Took a look at that and the folder item Exists is true, Alias is also true. I see nothing that indicate the original file is missing.

If it is pointing to the alias and not the target, FolderItem.Alias should be true.

The fact that you used the option that resolves aliases, but you still have an alias, should indicate that it couldn’t resolve.