on 07-09-2010 12:59 PM
Hi all,
I have to upload a text file (In which all field datas are separated by Tab) in webdynpro View.Please give me the details how to do it.
Thanks in Advance
regards,
Ranjit
I got the answer and solved it.Thanks Ajay.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ranjit,
Please find the code below. Also, if you see any sysntax erros or typos, try to correct them when you implement this.
IWDResource resource = null;
String strFileExtn = null;
String strFileName = null;
InputStream inputStream = null;
FileOutputStream fout = null;
BufferedReader br = null;
File fp = null;
double fileSize = 0;
int ofst = 0;
int num = 0;
StringWriter sw = new StringWriter();
boolean returnState = true;
try
{
if(wdContext.currentContextElement().getFileResource() != null)
{
resource = wdContext.currentContextElement().getFileResource();
strFileExtn = resource.getResourceType().getFileExtension().toUpperCase();
strFileName = resource.getResourceName();
// create an input stream to read the resource.
inputStream = resource.read(false);
// get the file size.
fileSize = inputStream.available();
// Create the byte array to hold the data
byte[] bytes = new byte[(int)fileSize];
// Read in the bytes
while (ofst < bytes.length && (num = inputStream.read(bytes, ofst, bytes.length-ofst)) >= 0)
{
ofst += num;
}
fp = new File(strFileName);
fout = new FileOutputStream(fp);
fout.write(bytes);
fout.flush();
fout.close();
br = new BufferedReader(new FileReader(fp));
try
{
String txt = null;
int index = 0;
while (( txt = br.readLine()) != null)
{
//Get the Index for the 'Tab'
index = txt.indexOf('\t');
wdComponentAPI.getMessageManager().reportSuccess("Field -"+txt.substring(0, index) " +" Value -"+txt.substring(index,txt.length()));
}
}
catch (IOException ex)
{
}
}
catch(FileNotFoundException fe)
{
}
catch(IOException ioe)
{
}
catch(Exception e)
{
}
Regards,
Ajay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ranjit,
1.Add a 'file Upload' UI element to your Web Dynpro View.
2.Create a context attribute of type 'Resource' say 'FileResource' and bind it to the resource property of the file upload UI elemnt.
3. Create a button say 'Upload' and an action attached to it say 'Upload'
4.Write the following code in your 'Upload' action
IWDResource resource = null;
String strFileExtn = null;
String strFileName = null;
InputStream inputStream = null;
FileOutputStream fout = null;
BufferedReader br = null;
File fp = null;
double fileSize = 0;
int ofst = 0;
int num = 0;
StringWriter sw = new StringWriter();
boolean returnState = true;
try
{
if(wdContext.currentContextElement().getFileResource() != null)
{
resource = wdContext.currentContextElement().getFileResource();
strFileExtn = resource.getResourceType().getFileExtension().toUpperCase();
strFileName = resource.getResourceName();
// create an input stream to read the resource.
inputStream = resource.read(false);
// get the file size.
fileSize = inputStream.available();
// Create the byte array to hold the data
byte[] bytes = new byte[(int)fileSize];
// Read in the bytes
while (ofst < bytes.length && (num = inputStream.read(bytes, ofst, bytes.length-ofst)) >= 0)
{
ofst += num;
}
fp = new File(strFileName);
fout = new FileOutputStream(fp);
fout.write(bytes);
fout.flush();
fout.close();
br = new BufferedReader(new FileReader(fp));
try
{
String txt = null;
int index = 0;
while (( txt = br.readLine()) != null)
{
//Get the Index for the 'Tab'
index = txt.indexOf('\t');
wdComponentAPI.getMessageManager().reportSuccess("Field -"txt.substring(0, index) " Value -"+txt.substring(index,txt.ngth()));
}
}
catch (IOException ex)
{
}
}
catch(FileNotFoundException fe)
{
}
catch(IOException ioe)
{
}
catch(Exception e)
{
}
Regards,
Ajay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Use the file upload UI element. Create a button (for example "populate form"). Read the text file inside the action, and populate the view with corresponding data. If you search (even google), you'll find relevant threads. Hope this helps.
Thanks
Srinivas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.