Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > ASP CDO
|
ASP CDO As of Oct 5, 2005, this forum is now locked. No posts have been deleted. Please use "Classic ASP Professional" at: http://p2p.wrox.com/forum.asp?FORUM_ID=56 for discussions similar to the old ASP Pro Code Clinic or one of the other many remaining ASP and ASP.NET forums here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP CDO section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 7th, 2005, 06:08 AM
Registered User
 
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Rename attachments using CDO AddAttachment method

Hi everyone, my first post here,

I am creating an e-mail using the CDO object and using the AddAttachment method to attach a file from a URL. I am having a problem in that the file file attached is given a random name (something along the lines of ATXX412.pdf).

Does anyone know if it is possible to rename/assign a name to attached file before the e-mail is sent?

Any help would be much appreciated.
 
Old July 7th, 2005, 06:18 AM
Registered User
 
Join Date: Jul 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've sorted it now. Thanks.

 
Old July 28th, 2005, 06:13 PM
Registered User
 
Join Date: Jul 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've had the same question and can't find much about it (yet). It'd be great if you could post what you did to fix or work around this problem.

Restated, my problem is that files are named one thing on the server (say, "attachment02823.txt") and I need to attach them to an email under a different name (so the email has an attachment "instructions.txt").

Physically renaming the file on the server is not ideal, since the goal of renaming the files is to avoid filename collision. Any ideas?

 
Old September 16th, 2005, 03:10 AM
Registered User
 
Join Date: Sep 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

This is tricky but not impossible. The trick is to get hold of the bodypart object that represents the attachment and update that.

In the example below I simply add a prefix to the filename (my application required several files with identical names to be collected from different paths and emailed out).

The AddAttachment method does return a bodypart object but I find it easier to pull it from the end of the attachments collection as follows:-

.AddAttachment "file://C:\whatever\path" & fname
set iBp = iMsg.Attachments.Item (iMsg.Attachments.Count)

Once you've got the bodypart, you can update the FileName attribute of the content-disposition header field thus:-


Set Flds = iBp.Fields
Flds("urn:schemas:mailheader:content-disposition") = "attachment; filename=""Prefix_" & fname & """"
Flds.Update

That's it! Your attachment now has a new name.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use rename method ajeshss C# 1 February 23rd, 2012 08:14 PM
LNC Rename dmoffice Access VBA 6 November 16th, 2006 09:42 PM
Rename node name venutm XML 0 March 9th, 2006 03:36 PM
Rename table collie Access 1 February 23rd, 2005 02:49 PM
Can't rename a report bmurrin Access 2 January 28th, 2004 07:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.