469,890 Members | 1,440 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,890 developers. It's quick & easy.

Copy Images to a word File

Hello,
I need to copy images from a folder and copy to a word document. I
have done as follows.. but It copies only last image. Can any one of
you help me in this..
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Response.Buffer = True
Dim DirPath As String
DirPath = "D:\ASPDotNet\images\"
Dim FileName As String
Response.ContentType = "application/msword"
Response.AddHeader("Content-Disposition",
"inline;filename=TestImage.doc")
Dim FileList As String() = Directory.GetFiles(DirPath)

For Each FileName In FileList
Image1.Style.Item("Height") += 50
Image1.ImageUrl = FileName

Label1.Text = "this is Image No:" & i
Label1.Style.Item("Height") += 50
i = i + 1
Next
End Sub

Mar 2 '07 #1
11 2329
<sa************@gmail.comwrote in message
news:11**********************@t69g2000cwt.googlegr oups.com...
I need to copy images from a folder and copy to a word document. I
have done as follows.. but It copies only last image. Can any one of
you help me in this..
For Each FileName In FileList
Image1.Style.Item("Height") += 50
Image1.ImageUrl = FileName

Label1.Text = "this is Image No:" & i
Label1.Style.Item("Height") += 50
i = i + 1
Next
End Sub
Looks very much like you're populating the same control (Image1) each time
you loop through FileList...
Mar 2 '07 #2
On Mar 2, 8:49 pm, "Mark Rae" <m...@markNOSPAMrae.comwrote:
<sandeepkedl...@gmail.comwrote in message

news:11**********************@t69g2000cwt.googlegr oups.com...
I need tocopyimages from a folder andcopyto a word document. I
have done as follows.. but It copies only lastimage. Can any one of
you help me in this..
For Each FileName In FileList
Image1.Style.Item("Height") += 50
Image1.ImageUrl = FileName
Label1.Text = "this isImageNo:" & i
Label1.Style.Item("Height") += 50
i = i + 1
Next
End Sub

Looks very much like you're populating the same control (Image1) each time
you loop through FileList...
Yes.. But I tried to Dynamically create the Image (dim img as Image)
then assign the values.. img.ImageURL=FileName still the same result..

Mar 5 '07 #3
"Sandy" <sa************@gmail.comwrote in message
news:11*********************@t69g2000cwt.googlegro ups.com...
>Looks very much like you're populating the same control (Image1) each
time
you loop through FileList...

Yes..
Er, well there's your problem right there...!
But I tried to Dynamically create the Image (dim img as Image)
then assign the values.. img.ImageURL=FileName still the same result..
Post your changed code...
Mar 5 '07 #4
I have changed the code to dyanamically create the Image. Still No
success.
The Changed code is:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim DirPath As String
DirPath = "D:\ASPDotNet\images\"
Dim FileName As String
Response.ContentType = "application/msword"
Response.AddHeader("Content-Disposition",
"inline;filename=TestImage.doc")
Dim FileList As String() = Directory.GetFiles(DirPath)
For Each FileName In FileList
image2.ID = i
image2.ImageUrl = FileName
image2.Style.Item("Height") += 50
Next
End Sub
If I do like this only last one is Copied and also Image is not
displayed properly.


On Mar 6, 12:12 am, "Mark Rae" <m...@markNOSPAMrae.comwrote:
"Sandy" <sandeepkedl...@gmail.comwrote in message

news:11*********************@t69g2000cwt.googlegro ups.com...
Looks very much like you're populating the same control (Image1) each
time
you loop through FileList...
Yes..

Er, well there's your problem right there...!
But I tried to Dynamically create theImage(dim img asImage)
then assign the values.. img.ImageURL=FileName still the same result..

Post your changed code...

Mar 8 '07 #5
"Sandy" <sa************@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...
>I have changed the code to dyanamically create the Image.
Not as far as I can see...
For Each FileName In FileList
image2.ID = i
image2.ImageUrl = FileName
image2.Style.Item("Height") += 50
Next
Every time the above For loop iterates, it is overwriting the image2
variable, not creating a new image variable...
Mar 8 '07 #6
If I use like blow it does not copy anything into word.
Dim i As Integer = 0
For Each FileName In FileList

Dim image(i) As System.Web.UI.WebControls.Image
image(i) = New System.Web.UI.WebControls.Image
image(i).ID = i
image(i).ImageUrl = FileName
i = i + 1
Next
Mar 12 '07 #7
"Sandy" <sa************@gmail.comwrote in message
news:11**********************@64g2000cwx.googlegro ups.com...
If I use like blow it does not copy anything into word.
Dim i As Integer = 0
For Each FileName In FileList

Dim image(i) As System.Web.UI.WebControls.Image
image(i) = New System.Web.UI.WebControls.Image
image(i).ID = i
image(i).ImageUrl = FileName
i = i + 1
Next
Well it wouldn't do... For each iteration through the above loop you are:

- dimensioning an image variable
- instantiating a new image variable
- assigning it an ID
- populating its ImageUrl variable
- incrementing a counter

You don't appear to be actually doing anything with the image variables
other than creating them... Please show the code where you are trying to add
them to the Word document...
Mar 12 '07 #8
I'm not sure how to add..That is what I's missing...

Mar 12 '07 #9
I'm not sure how to add..That is what I's missing...

Mar 12 '07 #10
"Sandy" <sa************@gmail.comwrote in message
news:11**********************@c51g2000cwc.googlegr oups.com...
I'm not sure how to add..That is what I's missing...
Ah, right...

Firstly, don't even think about using server automation with ASP.NET - it's
not supported by Microsoft, and will almost certainly cause you huge
problems sooner or later...

Basically, if you want to create and stream Word content with ASP.NET, there
are three ways:

1) Use HTML
Word, like Excel and PowerPoint etc, supports HTML as a file format...

a) Open up Notepad and copy the following text:

<html>

<head>
<title>I'm not really a Word doc, but I look like one</title>
</head>

<body>
Hello world!
</body>

</html>

b) Save the Notepad file with a .doc extension

c) Double-click on the file you just created - what happens...? Word
launches and displays the file just like a "real" Word document. The only
potential problem with this would be the images themselves, because you
can't embed images in HTML - that will mean that they will need to reside on
a webserver somewhere that your users can see...
2) Use XML
Word 2003 & 2007 supports the XML file format:
http://www.microsoft.com/downloads/d...displaylang=en
http://www.microsoft.com/downloads/d...displaylang=en

ASP.NET and XML are "made for each other", so you can use the standard XML
namespace to create Word documents. However, even if you are fairly familiar
with XML, this can be quite difficult.
3) Use Aspose
http://www.aspose.com/Products/Aspos...s/Default.aspx

This is easy to use and very powerful, but not free... However, it will
allow you to embed the images into the Word document because it will create
true Word documents in the native Word file format...
Mar 12 '07 #11
Thank you Mark..

Apr 11 '07 #12

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.