Domino附件分开存取实例(转载)

import java.util.Vector;

import lotus.domino.AgentBase;
import lotus.domino.AgentContext;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.Session;

/**
* @类名:SaveToPic
* @功能:将本文档中的附件保存到图片库
* @author wnight88
* @时间: 2009-4-10
*/
public class SaveToPic extends AgentBase
{

public void NotesMain()
{

try
{
Session session = getSession();
AgentContext agentContext = session.getAgentContext();

//当前文档
Document currentDoc = agentContext.getDocumentContext();
//图片库文档的ID号,若没有则为空
String picDocUnid = currentDoc.getItemValueString("picDocUnid");


//当前数据库及视图、视图中对应的文档
Database thisDB = agentContext.getCurrentDatabase();
Document thisDoc = thisDB.getDocumentByUNID(currentDoc.getUniversalID());

//图片库的文档,创建及追加
Database goalDB = session.getDatabase(thisDB.getServer(), "whcg\\wjkhPic.nsf");
Document goalDoc = null;
if(picDocUnid.equals(""))
{
goalDoc = goalDB.createDocument();
thisDoc.copyAllItems(goalDoc,true);
goalDoc.replaceItemValue("form", "newPic");
goalDoc.replaceItemValue("unid", thisDoc.getUniversalID());
goalDoc.save(true,true);
}
else
{
goalDoc = goalDB.getDocumentByUNID(picDocUnid);
thisDoc.copyAllItems(goalDoc,false);
goalDoc.save(true,true);
}

//读取附件列表,写入到连接域中
Vector fileNames = session.evaluate("@AttachmentNames", goalDoc);
String url = "";

for (int i = 0; i < fileNames.size(); i++)
{
url = url + "<br>" + "<img src='/whcg/wjkh.nsf/doclist.gif'><a href='/whcg/wjkhPic.nsf/0/"
+ goalDoc.getUniversalID() + "/$FILE/"
+ fileNames.get(i) + "'>" + fileNames.get(i)
+ "</a>";
}

String htmlString = "";
htmlString = htmlString
+ "<table class=tbbg align=center border=0 cellpadding=2 cellspacing=1>";
htmlString = htmlString + "<tr class=toptrbg>";
htmlString = htmlString + "<td>附件列表:</td>";
htmlString = htmlString + "</tr>";
htmlString = htmlString + "<tr>";
htmlString = htmlString
+ "<td bgcolor=f8f8f8>";
htmlString = htmlString + url;
htmlString = htmlString + "</td>";
htmlString = htmlString + "</tr>";
htmlString = htmlString + "</table>";

thisDoc.replaceItemValue("attachmentList", htmlString);
//删除原文档中的附件
if(thisDoc.getFirstItem("$File") != null)
{
thisDoc.getFirstItem("$File").remove();
}
thisDoc.replaceItemValue("picDocUnid", goalDoc.getUniversalID());
thisDoc.save(true,true);

}
catch (Exception e)
{
e.printStackTrace();
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值