Shapes.AddPicture(...) new images are ignored

M

MediaMogul

The title isn't very clear, but it's difficult to sum up what I mean in so
few characters. Anyway, it's like this. I have a file on the file system
called animals.jpg. I paste it into the powerpoint pres. using the following
line of code:

PowerPointApp.ActivePresentation.Slides.Item(currentSlide).Shapes.AddPicture(filePath,
Office.MsoTriState.msoTrue, Office.MsoTriState.msoTrue, 5, 5, width, height)

after this, I delete the file animals.jpg. I then save another image under
the same name in the same folder (i.e. filename and path are the same, but
the image is actually a new one). I know that the new file has been saved
where the old one was because I was able to open it a look at the image
during debugging. Secondly, debugging showed me that the width and height of
the new image had been used when I wrote these lines of code:

Image image = Image.FromFile(filePath);
int width = image.Width;
int height = image.Height;

So the problem is as follows: when I put this new image into the
presentation, it's the original image that is getting pasted in, not the new
one. I have the old picture twice. Why would this happen? The old image has
already been removed fromthe file system. Is it being cached somehow, and not
actually read from the file system at all?

In any case, it seems pretty daft. As a test, I shall append
DateTime.Now.toString() onto the filenames to at least have a new filename on
the second (and any further) occassions. Maybe this will force powerpoint to
really check out what's on the file system...

I don' think that that is the way to solve this really, but will ppost back
as soon as I have tested it.

Does anyone have an idea what's causing this problem? Thank you in advance,
D.
 
M

MediaMogul

using a different file name worked, which suggests to me that previously the
original file was getting cached and re-used even thought the file had been
replaced on the file system by a similarly named one. If that's the case, it
seems pretty daft to me, but there you go.
 
M

MediaMogul

Cheers Steve,

Although what PPT des might be 'clever', it had me messing around with code
that essentially should have worked 'sans workaround' for rather a while.
Well, my problem is solved. I just hope that if someone with a similar
problem reads this, they will save some time. :)

Thanks for your response, MM.
 
M

MediaMogul

....Just a thought - should PPT consider comparing the exact size of the two
files, this complication would be in the vast majority of cases avoided -
it's highly unlikely that two files that happen to have the same name are
going to have precisely the same number of bits in them. One could also
suggest a bitwise comparison...but that obviously has a much larger overhead
and I guess would be considered overkill. :)

MM
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top