I am using aspose.slides to create PPTx's. Some of the process involves loading jpg's from another server and including them in the presentation. This works fine in my development environment. When I upload the site to its server, the jpg loading fails.
I am using code found on your site somewhere which starts by creating a stream:
oFS = New FileStream(sFile, FileMode.Open, FileAccess.Read)
This causes an access violation error when run from the server.
I also boiled the code down to reading the file directly:
oImg = System.Drawing.Bitmap.FromFile(sFilePath)
This causes a file not found error.
We have narrowed the problem down to the fact that the File Path has a space in it. How does one solve this problem (while still keeping the space, there is a lot of legacy data)? I have tried replacing the space with %20 or +. I have tried using Server.UrlEncode. The error message always comes back with the encoding in place (like no decoding is happening).
Help!!!
Dear Brad,
Thanks for using Aspose.Slides.
Please use ‘@’ before your file path as mentioned in example code snippet below.
oFS = New FileStream(@"D:\\PPT Presentations\\Pres1.ppt", FileMode.Open, FileAccess.Read)
If the problem still persists, please feel free to share with us.
Thanks and Regards,
Mudassir,
Thanks for your reply.
My file names are in a variable. How does the @ get added to that?
When I put:
oImg = System.Drawing.Bitmap.FromFile(@sFilePath)
I get a compile error "Expression Expected"
If I put the @ in the variable:
sFilePath = "@" + sFile
oImg = System.Drawing.Bitmap.FromFile(sFilePath)
I get file not found.
Brad
Also tried:
sFilePath = "@""" + sFile + """"
oImg = System.Drawing.Bitmap.FromFile(sFilePath)
Which yields:
sFilePath = "@"\\rtselp-fs01\final art\PATRIOT\SYS\JPG\P-SYS-0143_L.jpg""
Gave error = Illegal characters in path
oFS = New FileStream(@"\\rtselp-fs01\final art\PATRIOT\SYS\JPG\P-SYS-0143_L.jpg", FileMode.Open, FileAccess.Read)
Gives compile error = Expression expected
Dear Brad,
I have been able to successfully execute the following statements with no errors. Can you please verify the things on your end ?
String sFilePath1 = "D:/ppt and pptx/NewImage.jpeg";
String sFilePath = "d:\\ppt and pptx\\Sunset.jpeg";
Image oImg = System.Drawing.Bitmap.FromFile(@sFilePath);
oImg.Save(@sFilePath1);
Thanks and Regards,
Hello Brad,
The character, ‘@’ does not work in case of VB.NET. I have used the following code snippet to access an image file from a PC on LAN network and it worked for me. Please follow the code snippet below.
Dim sFilePath As String = "\\MUDASSIR-PC\ppt and pptx\Sunset.jpeg"
Dim oImg As System.Drawing.Image = System.Drawing.Bitmap.FromFile(sFilePath)
I am using Microsoft Visual Studio 2005 with .NET frame work 2.0.5 installed.
In case, If you are passing the file path to some function as an argument, then you need to add quotes with the path as given in code snippet below.
Dim sFilePath As String = """\\MUDASSIR-PC\ppt and pptx\Sunset.jpeg"""
We are sorry for your inconvenience,
Thanks for looking at this.
If I put:
sFilePath = "\\rtselp-fs01\final art\PATRIOT\SYS\JPG\P-SYS-0143_L.jpg"
This line:
oFS = New FileStream(sFilePath, FileMode.Open, FileAccess.Read)
Gives this run error:
Access to the path '\\rtselp-fs01\final art\PATRIOT\SYS\JPG\P-SYS-0143_L.jpg' is denied.
or
oImg = System.Drawing.Bitmap.FromFile(sFilePath)
Gives this error:
FileNotFoundException: \\rtselp-fs01\final art\PATRIOT\SYS\JPG\P-SYS-0143_L.jpg
If I use:
sFilePath = """\\rtselp-fs01\final art\PATRIOT\SYS\JPG\P-SYS-0143_L.jpg"""
oFS = New FileStream(sFilePath, FileMode.Open, FileAccess.Read)
or oImg = System.Drawing.Bitmap.FromFile(sFilePath)
Both give:
Illegal characters in path.
I am using Visual Studio 2008, .Net 3.5 SP1
Don't know where to go now. We are talking about changing the share to one without spaces. That would do it this time.
Hi Mudassir,
Thinking overnight about your last post. That code also works for me when running from the development environment (the first version). It does not work when I put the site on its server. I'm thinking it may be a change required on the server. If we can't resolve it there, we will just change the path to one without spaces.
If we do get a resolution, I will post it here.
Again, thanks for your help.
Brad
Thanks to all who tried to help.
Turned out this has nothing to do with the space. It is a permissions issue on the jpg server. Our server guy finally opened up access to everyone and the space did not matter; it did return the jpg file.
Why the call would work from the dev env and not the web server is still a mystery. Why the jpg could be displayed but not accessed via the FileStream call is still unknown.