473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 2572
<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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Risto Heinonen | last post by:
Hi. I have a web page that has images and text. I can carefully select one image and the on the right of the image and then copy & paste to Word. Is it possible to make javascript do the same:...
2
by: Guillaume Durand | last post by:
Hi, I transform XML data in an OutputStream which is open as a word document. All works fine excepted the images defined in the xsl file which are html links (src="images/image1.jpg"). So, when...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
0
by: Robert | last post by:
Hi! I want to fill the clipboard programmatically in oder to manual copy the data to word. The data consists of cells of a grid which contains text or images. Using the standard copy/paste of...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.