Sudheer, can you use Java?
Here's a webject that will get you the URL. You want the urlLocation value. To make sure you have the primary content, check isPrimary = true, otherwise the record you're looking at may be a secondary attachment:
<%@page language="java"%>
<%@taglib uri="
prefix="ie"%>
<%
String obid = (String)getContextGroup("FORM").getAttributeValue(0,"obid");
//get the windchill instance
String windchill = wt.util.WTProperties.getLocalProperties().getProperty("wt.federation.ie.VMName");
%>
<ie:webject name="List-ContentItems" type="OBJ">
<ie:param name="instance" data="<%=windchill%">" valueSeparator=";" delim=";" default="windchill"/>
<ie:param name="object_ref" data="<%=obid%">" delim=","/>
<ie:param name="attribute" data="*"/">
<ie:param name="group_out" data="contentItems" default="output"/">
</ie:webject>
<ie:webject name="Return-Groups" type="GRP">
<ie:param name="GROUP_IN" data="*"/">
</ie:webject>
Here's some Java to wrap this with, if it's useful to you:
public static String getContentUrl(String obid) {
// Fire task to grab attachments
try {
Task theTask = new Task("/getContentInfo.xml");
theTask.addParam("obid", obid);
theTask.invoke();
// Get the group out of the response
Group contentItems = theTask.getGroup("contentItems");
// Loop through the results until you find a urlLocation
int count = contentItems.getElementCount();
for (int i = 0; i < count; i++) {
Boolean isPrimary = Boolean.valueOf((String) contentItems.getAttributeValue(i, "isPrimary"));
if (isPrimary != null && isPrimary.booleanValue()) {
String contentURL = (String) contentItems.getAttributeValue(i, "urlLocation");
if (contentURL != null)
return contentURL;
}
}
} catch (IEException e) {
System.err.println("Error executing getContentInfo.xml webject.");
log.error(e.getMessage(), e);
} catch (IOException e) {
System.err.println("Error accessing getContentInfo.xml webject.");
log.error(e.getMessage(), e);
}
return null;
}
Once you do all that, you should be able to just download the file using an HttpClient, something along the lines of this:
HttpClient client = new HttpClient();
client.getState().setCredentials(
new AuthScope("windchill.mycompany.com", 80),
new UsernamePasswordCredentials("username","password"));
get = new GetMethod(getContentUrl(obid));
get.setDoAuthentication(true);
client.executeMethod(get);
byte[] documentBytes = get.getResponseBody();
get.releaseConnection();
-Thomas R. Busch
Sr. Software Developer
Stryker Instruments
(269) 323-7700 x4014
tom.busch@stryker.com<
">mailto:tom.busch@stryker.com>