on 05-05-2010 8:37 AM
In My view I have create a context node(ctx_va_FileData) with value attribute (ctx_va_FileResource) of type ,Resource.
Select the Simple Type, navigate to Dictionaries u2192 Local Dictionary u2192com.sap.ide.webdynpro.uielementdefinitions and select Resource.
In View part of Layout :Create one u201CFileUpload u201C UI with Create one LinkToAction IU element and assign u201CaUploadFileinto_KMu201D action to this action
Coding Part in Web Dynpro java
Step 1:
Go to the wdDoInit() method and paste the following code
public void wdDoInit()
{
//@@begin wdDoInit()
try {
IPrivateUploadFile_KMView.ICtx_vn_FileDataElement element = wdContext.createCtx_vn_FileDataElement();
if (element != null)
{
wdContext.nodeCtx_vn_FileData().bind(element);
}
}catch (Exception e) {
wdComponentAPI.getMessageManager().reportSuccess("Error: " + e.getCause().toString());
}
//@@end
}
Go to the onActionaUploadFileinto_KM and paste the following code
public void onActionaUploadFileinto_KM(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionaUploadFileinto_KM(ServerEvent)
msgMgr = wdComponentAPI.getMessageManager();
IPrivateUploadFile_KMView.ICtx_vn_FileDataElement element =
wdcontext.currentCtx_vn_FileDataElement();
IWDResource resource = element.getCtx_va_FileResource();
if(resource!=null){
try {
//To get the Current User
IWDClientUser wdClientUser = WDClientUser.getCurrentUser();
com.sap.security.api.IUser sapUser = wdClientUser.getSAPUser();
com.sapportals.portal.security.usermanagement.IUser ep5User =
WPUMFactory.getUserFactory().getEP5User(sapUser);
ResourceContext resourseContext = new ResourceContext(ep5User);
//Portal KM Path
RID pathRID = RID.getRID("/documents/SDN"); //Root Directory
IResourceFactory resourseFactory =
com.sapportals.wcm.repository.ResourceFactory.getInstance();
ICollection collection = (ICollection)resourseFactory.getResource(pathRID,
resourseContext);
//Read the File
InputStream stream = resource.read(true);
String resourceName = resource.getResourceName();
String resourceExtn = resource.getResourceType().getFileExtension();
//KM Content
Content cont = new Content(stream,"application/octet-stream",-1,"UTF-16");
//create a file in above mentioned path in KM
com.sapportals.wcm.repository.IResource new_resource =
(com.sapportals.wcm.repository.IResource)collection.
createResource(resourceName, null, cont);
//Get the File length
long contentLen = new_resource.getContent().getContentLength();
//If no data in file
if(contentLen <= 0){
msgMgr.reportException("No data in file" , true);
}else {
msgMgr.reportMessage(IMessageUploadFile_KMComp.SF__UPLOAD,
new Object[] {resourceName},true);
}
} catch (NotSupportedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AccessDeniedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (WDUMException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ResourceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ContentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UserManagementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else
msgMgr.reportException("No file Selected ,Browse the file!",true);
element.setCtx_va_FileResource(null);
}//End of Action
But in the onActionaUploadFileinto_KM part IUser is deprecated and i m stuck at that point.
Plz provide me the solution and is there ant alternative solution for this and MY Portal is EP6 Nwds version is 7.0.9
Hi,
try the following code:
IWDClientUser wdcu = WDClientUser.getCurrentUser();
StringTokenizer stkUserName = new StringTokenizer(wdcu.getClientUserID(),":");
while (stkUserName.hasMoreElements())
{
strUserID = stkUserName.nextToken();
}
Regards,
Poojith MV
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sukalyan,
Have you checked the below links?
These will give you step by step implementation procedure.
http://wiki.sdn.sap.com/wiki/display/WDJava/KmuploadusingWebdynproapplication
Regards,
Sandip
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.