on 10-14-2005 4:31 PM
Hi, I want to upload a file. I have search in the forum and tried the different solutions.
Those are the steps I have following:
- in the context I have create a node with an attribute FileName (String) and FileData (binary).
- in the properties of the FileUpload's UIElement: data->File.FileData, fileName -> File.FileName
- in the wdInit():
IWDAttributeInfo attInfo = wdContext.nodeFile().getNodeInfo().getAttribute("FileData");
ISimpleTypeModifiable type = attInfo.getModifiableSimpleType();
IWDModifiableBinaryType binaryType = (IWDModifiableBinaryType) type;
- In the button associated to the upload:
try {
String location = "C://";
String file = wdContext.currentFileElement().getFileName();
String fileName = location +file;
File dest_file = new File(location,file);
FileOutputStream out = new FileOutputStream(dest_file);
if(wdContext.currentFileElement().getFileData() != null)
out.write(wdContext.currentFileElement().getFileData());
else
wdComponentAPI.getMessageManager().reportSuccess("The data is null");
out.close();
}
catch (FileNotFoundException e) {
wdComponentAPI.getMessageManager().reportSuccess("The Error"+e.getMessage());
}
catch (IOException e) {
wdComponentAPI.getMessageManager().reportSuccess("The Error"+e.getMessage());
}
When I deploy the application I get the following error:
The ErrorC:\work\pass red.txt (The system cannot find the path specified)
While debuging I have find out that the error is in the following code line:
FileOutputStream out = new FileOutputStream(dest_file);
, but I don't find the error or what is wrong with the code.
Would any of you help me?
Thanks
Hi,
I think one more "\" is required in the file path.
Ex : "C:\work\pass\red.txt "
Regards, Anilkumar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Resolved
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello again,
no, it didn't ends with exception, it's all ok, but it didn't create the directory.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Refer this link
follow the tutorial
File Upload/Download 23 | 30
Regards,
RK
Hi Valery, thanks for your answer.
I have tried with your code but it doesn't do anything... I have no idea why.
Thanks anyway.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mirera,
FileOutputStream constructor may fail if:
1. There is a security restrictions for accessing file system (hardly to be a case here)
2. There is a directory with the same name as file on the path
3. Some of directories on the path do not exist.
So, I guess your case is 3. So try the following code to write a file:
public static void create(final String name, final byte[] content) throws IOException
{
final String theName = name.replace('\', '/');
final int lastSeparator = theName.lastIndexOf( '/' );
final File dir;
final File file;
if ( lastSeparator > 0 )
{
dir = new File( theName.substring(0, lastSeparator) );
file = new File( dir, theName.substring( lastSeparator + 1) );
}
else
{
dir = new File( "." );
file = new File( dir, theName.substring( 0 == lastSeparator ? 1 : 0 ) );
}
if ( !dir.exists() ) dir.mkdirs();
final FileOutputStream fos = new FileOutputStream( file );
try
{
fos.write( content );
}
finally
{
try { fos.close(); } catch (final IOException ex) {}
}
}
Invoke it as:
final byte[] content =
{'H','e','l','l','o',',',' ','W','o','r','l','d','!'};
create("C:\some-x\Some File.txt", content);
VS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
helo Mireia
instead of
String location = "C://";
write
String location = "C:
";
i think this should work.
Regards,
Piyush.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
thanks all for your answers. It seems (I don't know why) that I can only put in the path the root of the local directory (without folders).
Also, although I haven't any errors while deploying the application, I don't get a copy of my upload file as a result... any suggestion would be highly appreciate.
hi
the loc should be given as "c:
filename.doc". Other than this nothing seems to be wrong.
regards
vln
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mireia
one of the the options, try with the following path
C:
work
pass
red.txt
Regards
Pran
Message was edited by: Pran Bhas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
24 | |
11 | |
9 | |
7 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.