Windchill上传本地⽂件⾄⽂档中
/**
* 上传本地附件⾄⽂档附件
* @param localFile
* @param branchId
* @throws Exception
*/
public String uploadFiles(File localFile,String branchId,String tetx_name,String node)
throws Exception {
String docUrl ="";
WTDocument document = DocumentByBranchId(branchId);
/
/设置主内容
ApplicationData appData = wApplicationData(document);
appData.setRole(ContentRoleType.SECONDARY);// 附件位置
appData = ContentServerHelper.service.updateContent(document, appData, AbsolutePath());
appData = (ApplicationData) PersistenceHelper.manager.save(appData);
// appData = (ApplicationData)fresh(appData);
String fileNameAppOld = FileName();
// String fileName = fileNameApp.substring(0, fileNameApp.lastIndexOf(".")); // 获取名称当⽂档名称
// docUrl = URL(document, fileNameApp);
// String fileNameApp = placeAll("\\+", "%2B"); // 特殊字符处理
String fileNameApp = CtSwUtils.urlStr2Ascii(fileNameAppOld); // 特殊字符处理
docUrl = "<a href=\"/Windchill/ptc1/delivery/dowmLoadDoc?docNumber=" + Number()+"&fileName="+fileNameApp+"\" title=\"点击下载\" target=\"_b docUrl = docUrl+" <a title='删除该附件' href='javascript:;' class =\""+node+"\" style ='color:red;text-decoration:none;' onclick='deleteFilefield(\""+branchId+"\",\""+fil // docUrl = "<span style ='border:1px solid #0000CC'>"+docUrl+"</span>";
return docUrl;
}
/**
* 删除⽂档附件
* @param localFile
* @param branchId
* @throws Exception
*/
public void deleteFiles(String branchId,String fileName)throws Exception {
WTDocument document = DocumentByBranchId(branchId);
// 单个主要内容 ContentRoleType.PRIMARY 附件 ContentRoleType.SECONDARY
QueryResult qr = ContentsByRole(document, ContentRoleType.SECONDARY);
while(qr !=null && qr.hasMoreElements()){
getsavefilenameContentItem item = (ContentItem) qr.nextElement();
if (item instanceof ApplicationData) {
ApplicationData appData = (ApplicationData)item;
System.out.println("Attachment File: " + FileName());
String appDataFileName =FileName();
if(CtFormatUtil.hasContent(appDataFileName) && appDataFileName.equals(fileName)) {
appData = (ApplicationData)PersistenceHelper.manager.delete(appData);
}
}
}
document = (WTDocument)fresh(document);
}
/**
* 获取⽂档附件
* @param docNumber
* @param fileName
* @return
* @throws Exception
*/
public ApplicationData getApplicationData(String docNumber,String fileName) throws Exception {
WTDocument document = DocumentByNumber(docNumber);
if(document != null) {
// 单个主要内容 ContentRoleType.PRIMARY 附件 ContentRoleType.SECONDARY
QueryResult qr = ContentsByRole(document, ContentRoleType.SECONDARY); while(qr !=null && qr.hasMoreElements()){
ContentItem item = (ContentItem) qr.nextElement();
if (item instanceof ApplicationData) {
ApplicationData appData = (ApplicationData)item;
System.out.println("Attachment File: " + FileName());
String appDataFileName =FileName();
if(CtFormatUtil.hasContent(appDataFileName) && appDataFileName.equals(fileName)) {
return appData;
}
}
}
}
return null;
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论