cancel
Showing results for 
Search instead for 
Did you mean: 

How to open a new word file on click of a link

Former Member
0 Kudos

Hi gurus,

I am having requirement for opening an new word document dynamically using a button.

It's urgent.

For correct answer reward points will be given.

Regards,

AK

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Check this code it will work

try

{

File f=new File("NewDocument1.doc");

FileOutputStream fos=new FileOutputStream(f);

FileInputStream fis = new FileInputStream(f);

FileChannel fc = fis.getChannel();

byte[] data = new byte[(int)(fc.size())];

IWDCachedWebResource cachedWebResource=WDWebResource.getWebResource(data,WDWebResourceType.DOC);

cachedWebResource.setResourceName("NewDocument1.doc");

String url=cachedWebResource.getURL();

IWDWindow window=wdComponentAPI.getWindowManager().createExternalWindow(url,"cmps",true);

window.open();

}

catch(Exception ioe)

{

wdComponentAPI.getMessageManager().reportSuccess(ioe.getMessage());

wdComponentAPI.getMessageManager().reportException("Exception in Method cmps :::"+ioe.getMessage(),false);

}

Former Member
0 Kudos

Hi,

Create a filedownload UI Element.In the context create a varialble "fileResource" of type com.sap.ide.webdynpro.uielementdefinitions.Resource.Bind the resource property of the filedownload element to created "fileResource" context variable.

In the doModifyView(),paste the following code

StringBuffer file = new StringBuffer();

byte[] data = file.toString().getBytes("UTF-8");

IWDResource resource = WDResourceFactory.createResource(data, "FileName",

WDWebResourceType.DOC);

wdContext.currentContextElement().setFileResource(resource);

Regards,

Sudhir

Former Member
0 Kudos

Hi,

Thank you for your reply.

But for me i need to open a word document in new window dynamically using a button.

Regards,

AK

Former Member
0 Kudos

Hi,

If you use a file download element you will get a link.If you click on that link file will get downloaded.If you have any problem post it.

Regards,

Sudhir

Former Member
0 Kudos

hi sudhir,

My requirement is to open a word document by clicking "submit" button.

We should not use office control,filedownload UIelements.

Actually what i have to do is,

i have to open an empty word document in new window on clicking a button.

Regards,

AK.

Edited by: akshay k on Feb 26, 2008 12:35 PM

Former Member
0 Kudos

Hi,

The best you can do is open the word document inside the browser. Follow these steps:

1. Create a new blank word document and call it for example "template.doc".

2. Switch to the Navigator view of the IDE & navigate to <your project name>/src/mimes/Components/<your component name> folder.

3. Paste the "template.doc" file inside this folder.

4. Now you can load this document in a new window by writing the following code in the eventhandler for the onAction event of the button:


try {
      String url = WDURLGenerator.getAbsoluteWebResourceURL(wdComponentAPI.getDeployableObjectPart(), "template.doc");
      wdComponentAPI.getWindowManager().createNonModalExternalWindow(url, "Word").show();
} catch (WDURLException e) {
      e.printStackTrace();
}

5. This will open word inside the browser with all the standard word functionalities loaded.

Regards,

Satyajit.

Former Member
0 Kudos

Hi,

Satyajit is right, we download resource dynamicly like this.

Best regards,

William

Former Member
0 Kudos

Hi,

make use of office control.

Pl go through the following blogs

/people/anilkumar.vippagunta2/blog/2007/02/04/office-control-in-webdynpro-ii

/people/anilkumar.vippagunta2/blog/2007/02/01/office-control-in-webdynpro--i

Regards

Ayyapparaj

Former Member
0 Kudos

Thanks for your reply,

For my requirement i have to use onaction to open new word document.

Regards,

AK