Link to home
Start Free TrialLog in
Avatar of harlanhugh
harlanhugh

asked on

Detaching Attachments from a Notes Database Automatically

I need an automated way to extract attachments (Word docs, PDF, PowerPoints, etcetera) from a Notes Database and put them into a local folder (C:\Attachments for example).

I can manually open the database and detach each attachment one by one, but this takes a long time and I need this to be done on a scheduled basis. The database will continue to be used and the attachments need to be updated regularly (once a day).

I am new to working with Notes, so please provide step by step instructions. From reading a little it seems there must be a way to use LotusScript to do this, but I am not sure where to begin to even start LotusScript. (How does one start a new LotusScript agent? How can I get it to run once a day? Etcetera.) Thanks.
ASKER CERTIFIED SOLUTION
Avatar of RanjeetRain
RanjeetRain

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RanjeetRain
RanjeetRain

See the accpeted answer code in the thread. That's a good code. You can easily adapt it to suit your needs, if any required. If you have any doubts, feel free to ask.
Step by step.. hmmmm. let me try :)

(1) Open designer
(2) Go to agents view
(3) Click new agent button at the top left
(4) Give a name to the agent
(5) Click shared agent
(6) Change the setting "When shoukd this agent run" to -- On schdule daily
(7) Click schedule and specify a time. Avoid using time between 1-4 a.m.
(8) Change the setting "Which document(s) should it act on" to -- All new and modified documents since last run
(9) In the lower pane (Actions), select lotus script.
(10) Paste the code from the accepted answer in the linked thread.
(11) Customize the agent as per your needs. Its less or more okay. You might not need a change other than the folder path where attchemnts should be kept after being detached etc
(12) Save the agent and come out

The server will run this agent daily now and your attchemnts will get detached on a daily basis.
Sandbox on notes.net has a utility which can be used to detach automatically and create a link to it on the file system..

I think this is the link ... (site is down now, validate it later) http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/fe7542cd3b120e1b00256c38004a6a27?OpenDocument

~Hemanth
Avatar of harlanhugh

ASKER

Thanks Ranjeet,

That looks like what I need.

Can you tell me how I would delete the contents of the folder prior to detaching all the documents into it? (The folder needs to be in sync - if attachments are removed from the database they must be removed from the folder also).

You mentioned that I should avoid between 1-4 a.m. Why? This seems like the ideal time to do it actually...

Also, if there are two attachments in separate documents with the same name, will this code create two different files or will one overwrite the other? Based on my interpreration of the code, it looks like it's going to name it using like this: PATH\FILENAME(NOTEID).EXT - if so, then that's great.

Finally, how does Notes handle thread priority? Will the server be really sluggish while this is running?

Hemanth, the code at the sandbox was not for email, and not quite right for what I need to do.
Oops - I meant that the code at the sandbox WAS for email specifically - I need something that works generically and does not change the database - just creates the folder. I think Ranjeet is almost there.
>> Can you tell me how I would delete the contents of the folder prior to detaching all the documents into it? (The folder needs to be in sync - if attachments are removed from the database they must be removed from the folder also).

No, the current code doesn't handle the case. That needs to be coded. And that depends a lot on the volume of data. Attachments from a database that can be in dozens at a time need to be handled differently than a database that may contain 1000s of attachments at a time. Pls specify your requirement in detail and I might be able to help.

Though a very clever trick can be that -- do your house keeping simultaneously. Store your attachment as soon as document is created in database (An agent can be trigerred to run on NEW and MODFIED since ....). Also, you may write a database level handler that runs on document deletion. You may get rid of unwanted attachments from the file system by trapping PostDelete event of database.


>> You mentioned that I should avoid between 1-4 a.m. Why? This seems like the ideal time to do it actually...

You got it right, That does seem like the ideal time to do such things. And precisely the reason Domino has chosen that time to do all the house keeping it does. Not that Domino won't run your agents if you schedule at that time. But yes, you can keep it much happier if you don't disturb it while it works to keep the service in shape.

>> if there are two attachments in separate documents with the same name, will this code create two different files or will one overwrite the other? Based on my interpreration of the code, it looks like it's going to name it using like this: PATH\FILENAME(NOTEID).EXT - if so, then that's great.

That has to be the approach. If it doesn't already do that, try modifying it. If you yourself can't, we will help.

>> Finally, how does Notes handle thread priority? Will the server be really sluggish while this is running?

Not really. Unless and untill you have 100s of 1000s of documents and they all contain a couple attachments, you won't be overwhelmng the server. If users try lookups on views while such an agent is running, they may expericence some lag, but that's natural. You can't avoid it. For smaller databases, you might not even notice it.

Regarding the deletion of the contents of the folder, the volume of data should be in the range of 500-5000 documents. I would prefer not to get too fancy with agents running on modification events, although long term I can see why that approach might be preferable. If you could just tell me how to delete all the files within the folder, which I can run before doing the detachment of all the documents, that will do just fine.
That isn't so difficult. Shell out to DELTREE command with a /Y switch. That will delete all the files contained in it. Syntax is:

DELTREE /y C:\Attachments\*.*


that's it.
Great. Thank you.
Oh, one more thing - how do I execute the shell command from LotusScript?
Just put this someplace its executing...

Shell "DELTREE /y C:\Attachments\*.*"