473,775 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

word automation vb.net

I've been building an application that will merge fields in a text file with
a word template, save the resulting word file out to the user's hard drive,
and then email the file as an attachment.

The problem I'm having is that I can't delete the word file I saved at the
end of the process due to the file being locked by the email process. It
appears to take longer than the code takes to complete due to virus checking
software that intercepts the mail before releasing it (at least that's what
I've narrowed it down to).

I don't want to leave the file around after the code has completed. And I
don't think I want to hold up the completion of the code process until the
email gets sent in case the email process takes longer on some machines than
others.

I'm not sure if there is a better way to handle the attachment in the code
so I don't have to save a file to the user's desktop. Or if I can use a
deattach process that I can trigger from code to delete the file later. Or
something else.

I've attached a snippet of the code below:

Thanks
Steve

------------

WordDoc.SaveAs( sSaveFileName)
Do While Not WordDoc.Saved
Application.DoE vents()
Loop
WordDoc.Close(W ord.WdSaveOptio ns.wdDoNotSaveC hanges)

' Email the Saved Merge Document.

Dim Fromaddress As New MailAddress("fr omaddress")
Dim Toaddress As New MailAddress("to address")
Dim myMail As New MailMessage(Fro maddress, ToAddress)
myMail.Subject = "test"
Dim AttachmentFile As Attachment = New Attachment(sSav eFileName)
myMail.Attachme nts.Add(Attachm entFile)
myMail.Priority = MailPriority.Hi gh
Dim client As New SmtpClient
client.Host = "hostaddres s"
client.Send(myM ail)

' Release the references.

WordMailMerge = Nothing
WordDoc = Nothing
WordApp = Nothing

' Delete the temporary files.

System.IO.File. Delete(sSaveFil eName)


Nov 27 '06
12 3457
Thanks -- that makes me feel better. I just couldn't think
of another way. I was afraid I was going to get a lot of
negative feedback for the method I chose!

Robin S.
-------------------------------
"Robinson" <bb*@bbb.comwro te in message
news:lq******** *************** *******@giganew s.com...
>
>So this is what I did: I created the files in my
application directory and named them with a specific
pattern, like Temp_yymmddhhmm ss.csv.

Then every time they started up the application,
it would delete any files it found in the application
folder with the pattern Temp_*.csv.

I do this with temporary files. Typically I generate a hundred or so
during an average running session, which are all in a user data directory.
This directory is cleaned during program startup.

Nov 28 '06 #11
I figured out a solution to my problem. After client.send, I issue a
mymail.dispose. It releases the hold on the file which allows me to delete
it.

Steve

-----

Dim Fromaddress As New MailAddress("fr omaddress")
Dim Toaddress As New MailAddress("to address")
Dim myMail As New MailMessage(Fro maddress, ToAddress)
myMail.Subject = "test"
Dim AttachmentFile As Attachment = New Attachment(sSav eFileName)
myMail.Attachme nts.Add(Attachm entFile)
myMail.Priority = MailPriority.Hi gh
Dim client As New SmtpClient
client.Host = "hostaddres s"
client.Send(myM ail
myMail.Dispose( )


"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:Nd******** *************** *******@comcast .com...
Thanks -- that makes me feel better. I just couldn't think
of another way. I was afraid I was going to get a lot of
negative feedback for the method I chose!

Robin S.
-------------------------------
"Robinson" <bb*@bbb.comwro te in message
news:lq******** *************** *******@giganew s.com...
So this is what I did: I created the files in my
application directory and named them with a specific
pattern, like Temp_yymmddhhmm ss.csv.

Then every time they started up the application,
it would delete any files it found in the application
folder with the pattern Temp_*.csv.
I do this with temporary files. Typically I generate a hundred or so
during an average running session, which are all in a user data
directory.
This directory is cleaned during program startup.



Nov 29 '06 #12
Woohoo! Thanks for letting us know.
Congrats.
Robin S.
--------------------------------------
"Steve" <s.*****@comcas t.netwrote in message
news:ua******** ******@TK2MSFTN GP03.phx.gbl...
>I figured out a solution to my problem. After client.send, I issue a
mymail.dispose. It releases the hold on the file which allows me to
delete
it.

Steve

-----

Dim Fromaddress As New MailAddress("fr omaddress")
Dim Toaddress As New MailAddress("to address")
Dim myMail As New MailMessage(Fro maddress, ToAddress)
myMail.Subject = "test"
Dim AttachmentFile As Attachment = New Attachment(sSav eFileName)
myMail.Attachme nts.Add(Attachm entFile)
myMail.Priority = MailPriority.Hi gh
Dim client As New SmtpClient
client.Host = "hostaddres s"
client.Send(myM ail
myMail.Dispose( )


"RobinS" <Ro****@NoSpam. yah.nonewrote in message
news:Nd******** *************** *******@comcast .com...
>Thanks -- that makes me feel better. I just couldn't think
of another way. I was afraid I was going to get a lot of
negative feedback for the method I chose!

Robin S.
-------------------------------
"Robinson" <bb*@bbb.comwro te in message
news:lq******* *************** ********@gigane ws.com...
>
So this is what I did: I created the files in my
application directory and named them with a specific
pattern, like Temp_yymmddhhmm ss.csv.

Then every time they started up the application,
it would delete any files it found in the application
folder with the pattern Temp_*.csv.

I do this with temporary files. Typically I generate a hundred or so
during an average running session, which are all in a user data
directory.
This directory is cleaned during program startup.



Nov 30 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
12088
by: mickeydisn | last post by:
Sub: C++ Word automation Extract text hello. I want extact text form a word document using a visual c++ programme. I have see a lot of documentation. and my analysis is that I must use a "word automation". I have foud a lot of exemple to use it but I need your precious help to
12
5532
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000 and office XP components installed. ie I have word/access/excel 2k/xp/2003 installed. I tried to do a usual access 2k to word 2k automation yet I get the error "Automation Error" "ClassFactory cannot supply requested class" when on late binding try...
6
3962
by: Colleyville Alan | last post by:
I have an application that has an Access table that stores the locations of slides in a Powerpoint file. This used to work fine when there were about 4 files and 200 slides. The database would open all four PPT files at once, and would loop through queriers for ever client and create custom presentations. Now there are 8 files, nearly 500 slides and the computer is bogging down with trying to open them all at once. I know that Access...
2
2615
by: kids | last post by:
Does anybody know any reason which could cause Ms. word automation to crash? I try to call word automation to open a document and use find and replace function. For some reason it works but I don't know why it crash some time.
4
7683
by: Daniel | last post by:
Hello, i have a problem with the word automation from c#. First, i want to mention, that i don't have any dependencies from word in my c#-project, i want to use the system.reflection model to handle the automation. So, i'm using the following code to create a new word document: ---Code---
0
6298
by: mharris | last post by:
I need help with merging two Word documents into one through C# code. The problem isn't so much getting the documents put into one as it is maintaining the appropriate formatting, or rather reformating, after the merge. This is a full description of my needs. I have a C# class library that creates two Crystal Reports, and then exports them to the harddrive as Word documents. One's orientation is landscape, the other is portrait. I then...
2
2624
by: Radek | last post by:
Hi, I have got such problem: in my directory "C:\folder" I have 3 files in MS WORD (having tables, images etc), these are: "1.doc", "2.doc", "3.doc". I want to write an application (C# of course) which will merge the contents of files which I will point ie. 1.doc and 2.doc into one file: "12.doc" I've just tried to find smth in MSDN help, and in google archive of programing groups but still I don't know how to do it:(
4
11134
by: Yohancef Chin | last post by:
Hi, Being fairly new to .NET I am looking for a way to call MS Word from an event on a webform, and after the user is finished save that created document to an SQL Server database. Has anyone done this? Does it seem possible? I followed the instructions from a sample on the Microsoft knowledge base but it only seems to work when creating a VB.NET Windows .EXE, not an VB.NET ASP app.
5
2527
by: Daniel Walzenbach | last post by:
Hi, I need to know how I could populate a word file from within ASP.NET and stream it out to some user (I can rely on all users have at least Word XP installed). The preferable solution would be to have a word template on the server which is populated in the asp.net application and then streamed out to the user. Also acceptable would be to open a template on the client's computer using automation and fill this file (if this is possible)....
10
3286
by: cj2 | last post by:
I open a word template in VB and add values to the bookmarks then save the document as as pdf. When I then go to close the document it pops up a save as dialog box. It's already saved the document in pdf and that is all I want done with it. How can I tell it to close the file without prompting me for anything? For Each row As DataRow In myDt.Rows Dim objWord As Application Dim objDoc As Document objWord =...
0
9622
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10268
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9916
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8939
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7464
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6718
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4017
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2853
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.