Join
Sign in
Search Options
Search Everything
Search Formats
Home
Blog
Resources
Forums
About Open XML
More ...
Home
»
Forums
»
Formats
»
WordprocessingML
»
Unable to add image in .NET 3.5 using C#
Re: Unable to add image in .NET 3.5 using C#
Formats
Discussions about working with different Open XML Formats
Get this RSS feed
Details
3
Replies
0
Subscribers
Posted
over 2 years ago
Options
Subscribe via RSS
Share this
WordprocessingML
Unable to add image in .NET 3.5 using C#
rated by 0 users
This post has
3 Replies |
0
Followers
Cloverfield
30
Posted by
Cloverfield
on
Fri, Aug 27 2010 9:25 AM
rated by 0 users
Post Points: 20
Unable to add image in .NET 3.5 using C#
Hope someone can help.
I am trying to add an image to a docx file using the SDK in a .net 3.5 application.
However, when I add the imagepart and try to populate the stream with the actual imagedata, no matter what I do, I get "Memorystream Not Expandable" exception thrown.
Initially tried multiple version of:
var imagePart = mainpart.AddNewPart<ImagePart>("image/jpeg", sigId);
using (var writer = new BinaryWriter(imagePart.GetStream()))
{
writer.Write(imageFileBytes);
writer.Flush();
}
The tried:
var imagePart = mainpart.AddImagePart(ImagePartType.Jpeg,sigId);
imagePart.FeedData(new MemoryStream(imageFileBytes,true));
Can anyone tell me why this is not working. The first snippet of code works in .NET 4.0.
Anyone done this in 3.5? Or are there any other way to get the actual imagepart into the doc?
Any help will be appreciated.
Cloverfield
30
Posted by
Cloverfield
on
Fri, Aug 27 2010 9:36 AM
rated by 0 users
Post Points: 5
Re: Unable to add image in .NET 3.5 using C#
Sorry, in THIS case it also does not work in .NET 4.0.
Cloverfield
30
Posted by
Cloverfield
on
Fri, Aug 27 2010 2:29 PM
rated by 0 users
Post Points: 5
Re: Unable to add image in .NET 3.5 using C#
And figured out it was a stream in a different routine about 3 levels up. Sigh.
CharlieDigital
35
Posted by
CharlieDigital
on
Mon, Aug 30 2010 11:50 AM
rated by 0 users
Post Points: 5
Re: Unable to add image in .NET 3.5 using C#
Common issue with usage of the MemoryStream constructors.
For an expandable stream, you must instantiate the MemoryStream using the empty constructor.
http://charliedigital.com
Page 1 of 1 (4 items)