how to set default location in browse tag - html

Am doing project in j2ee.I use Browse button. I need to fetch images/files from a folder inside my project folder, everytime.I wish to set my project's folder name as a default location for my browse button.How to do that?
am using tis following code in a jsp page:
and calling the value in servlet :
String image= (String) request.getParameter("img");
while browsing ,the whole path is getting displayed but only the name of the image is passing as value in the sevlet.How to get the entire path? or how to set my project folder as default location while browsing?

If this is rendering a standard
<input type="file".../>
Then you have no control over the default directory.
Using flash gains you a bit more control (filetype preset, single/multiple file selection etc.)
I'm not sure if Java Applets have more access/options, hopefully someone can advise.
PS. for the standard input tag, the browser will remember the last location you used, so you only need to navigate once, if you are uploading several files from the same directory.

I actually solved this problem with an interesting trick. Here's how...
Create an external vbscript include file called vbshelper.inc which contains the following code:
function stuffKeys(x)
Set wshShell = CreateObject("WScript.Shell")
wshShell.Sendkeys(x)
end function
Inside your HTML code header, place the following line as your first < Script> element...
< Script type="text/VBScript src="vbshelper.inc">
later, in your HTML code, create the button like this...
< input type="File" id="srcFile" onchange="go_do_something()" onclick="stuffkeys(' C:\Temp\*.txt~')">
Note the space before the C in ' C:\Temp*.txt~' and the tilde ~ after the .txt.

Related

HTML Filepicker without sending file itself - only filepath [duplicate]

How can I create a directory chooser in html page.
If I use input file element I can select file only, but I need to select directory instead.
I need to do this beacause the user should select a right path inside his computer.
Any solutions ?
Try this, I think it will work for you:
<input type="file" webkitdirectory directory multiple/>
You can find the demo of this at https://plus.google.com/+AddyOsmani/posts/Dk5UhZ6zfF3 ,
and if you need further information you can find it
here.
Can't be done in pure HTML/JavaScript for security reasons.
Selecting a file for upload is the best you can do, and even then you won't get its full original path in modern browsers.
You may be able to put something together using Java or Flash (e.g. using SWFUpload as a basis), but it's a lot of work and brings additional compatibility issues.
Another thought would be opening an iframe showing the user's C: drive (or whatever) but even if that's possible nowadays (could be blocked for security reasons, haven't tried in a long time) it will be impossible for your web site to communicate with the iframe (again for security reasons).
What do you need this for?
As of 2022 there is now a directory picker API:
https://developer.mozilla.org/en-US/docs/Web/API/Window/showDirectoryPicker
async function getDir() {
const dirHandle = await window.showDirectoryPicker();
// run code for dirHandle
}
In case if you are the server and the user (e.g. you are creating an app which works via browser and you need to choose a folder) then try to call JFileChooser from the server when some button is clicked in the browser
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle("select folder");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
This code snipped is from here
This is my solution. It is the same as the above answers but you should notice that webkitdirectory = "true".
<input id="design" type="file" webkitdirectory = "true" directory/>
I did a work around. I had a hidden textbox to hold the value. Then, on form_onsubmit,
I copied the path value, less the file name to the hidden folder. Then, set the fileInput box to "". That way, no file is uploaded.
I don't recall the event of the fileUpload control. Maybe onchange. It's been a while. If there's a value, I parse off the file name and put the folder back to the box. Of, course you'd validate that the file as a valid file.
This would give you the clients workstation folder.
However, if you want to reflect server paths, that requires a whole different coding approach.
This isn't provided by HTML because of the security risk. <input type='file' /> is closest, but not what you are looking for.
If you're still using IE11 on Windows 10, you may try this example that uses an ActiveX control to achieve what you want.
Again if the OS is Windows, you can use VB scripts to access the core control files to browse for a folder.
If you do not have too many folders then I suggest you use if statements to choose an upload folder depending on the user input details.
E.g.
String user= request.getParameter("username");
if (user=="Alfred"){
//Path A;
}
if (user=="other"){
//Path B;
}

vb.net how to add and load an html file from resource into webbrowser control

I have a webbrowser control on form2, and the things I'd like to do are:
How can I add an HTML file into resource ?
How can I load it from resource to webbrowser control when an if-condition is true, and make it visible in the webbrowser?
For example:
If dttest.Rows(0).Item(0).ToString = TextBox1.Text Then
webbrowser.navigate(resources and the html name page)
End If
I've already tried the webbrowser.navigate but I want to load the HTML page.
This work's for me and is tried and tested... I left the If condition out as it's not pertinent of what you are trying to accomplish. Also no need to call Navigate as when you set the Uri it should load the document.
Dim filename As String = "test.html"
With Me.WebBrowser1 'Change name to reflect your name
.ScriptErrorsSuppressed = True 'I was getting script errors from site
.Url = New Uri(String.Format("file:///{0}{1}{2}/", System.IO.Directory.GetCurrentDirectory(), "/Resources/", filename))
End With
Note
If the Copy to Output Directory is not set to Copy Always for your html file (file's) you need to make that change. You can right click on the html file and select properties. Change that property as needed.

Set file path for input type="file"

Can we set the file path in javascript for
<input name="pictureUL" type="file" value="upload" onChange="this.form.submit()"/>
without opening the select file dialog box?
I have 2 buttons SCAN and FIND. ADD button opens dialog box asking user to select the file which will be uploaded to the server. SCAN button has to scan the document and upload it to the server. Scanning is fine but to submit the form i need to set the file path in the file tag as i am submitting the form there. Is there a way to do it?
Thanks in advance.
Due to possibly security issues, modern browsers do not allow you to access the file path or modify the value of an <input type="file">. You also cannot view the file path, as it will display C:\fakepath\yourfilename.yourfilextension.
You can't do it directly but you can create your new Filelist using a DataTransfer object, and if you wish you can copy your data into it to and create a duplicate with the specific change you want to make.
let file = new File([blob], fileName);
let list = new DataTransfer();
list.items.add(file);
You can then set it as the file attribute of the DOM node:
fileInput.files = myFileList;

using VW7.8/Jun789 JunFileDialog for file save and want to remember selected directory for next time

I am using VW7.8/Jun789 JunFileDialog for a file save as and want to remember/set the selected directory for next time. I am following JunFileDialog class example5. I suppose doing so in the onAccept: block should be possible, but so far I've had no success.
I'm having trouble understanding where or how to set the initialDirectory other than as per the example in the JunFileDialog>>request: messageString initialDirectory: directoryFilename initialFile: filenameString fileTypeMenu: aMenu initialFileType: fileType onAccept: acceptBlock onCancel: cancelBlock.
Is there a better file save dialog to use?
you can use VisualWorks' Dialog class. On class side it has the "file name dialogs" protocol. There you can find methods like #requestFileName:default: or #requestNewFileName:default:. Both should display a native dialog on Windows and Mac OS X which defaults to the last opened folder.

Directory Chooser in HTML page

How can I create a directory chooser in html page.
If I use input file element I can select file only, but I need to select directory instead.
I need to do this beacause the user should select a right path inside his computer.
Any solutions ?
Try this, I think it will work for you:
<input type="file" webkitdirectory directory multiple/>
You can find the demo of this at https://plus.google.com/+AddyOsmani/posts/Dk5UhZ6zfF3 ,
and if you need further information you can find it
here.
Can't be done in pure HTML/JavaScript for security reasons.
Selecting a file for upload is the best you can do, and even then you won't get its full original path in modern browsers.
You may be able to put something together using Java or Flash (e.g. using SWFUpload as a basis), but it's a lot of work and brings additional compatibility issues.
Another thought would be opening an iframe showing the user's C: drive (or whatever) but even if that's possible nowadays (could be blocked for security reasons, haven't tried in a long time) it will be impossible for your web site to communicate with the iframe (again for security reasons).
What do you need this for?
As of 2022 there is now a directory picker API:
https://developer.mozilla.org/en-US/docs/Web/API/Window/showDirectoryPicker
async function getDir() {
const dirHandle = await window.showDirectoryPicker();
// run code for dirHandle
}
In case if you are the server and the user (e.g. you are creating an app which works via browser and you need to choose a folder) then try to call JFileChooser from the server when some button is clicked in the browser
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle("select folder");
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
This code snipped is from here
This is my solution. It is the same as the above answers but you should notice that webkitdirectory = "true".
<input id="design" type="file" webkitdirectory = "true" directory/>
I did a work around. I had a hidden textbox to hold the value. Then, on form_onsubmit,
I copied the path value, less the file name to the hidden folder. Then, set the fileInput box to "". That way, no file is uploaded.
I don't recall the event of the fileUpload control. Maybe onchange. It's been a while. If there's a value, I parse off the file name and put the folder back to the box. Of, course you'd validate that the file as a valid file.
This would give you the clients workstation folder.
However, if you want to reflect server paths, that requires a whole different coding approach.
This isn't provided by HTML because of the security risk. <input type='file' /> is closest, but not what you are looking for.
If you're still using IE11 on Windows 10, you may try this example that uses an ActiveX control to achieve what you want.
Again if the OS is Windows, you can use VB scripts to access the core control files to browse for a folder.
If you do not have too many folders then I suggest you use if statements to choose an upload folder depending on the user input details.
E.g.
String user= request.getParameter("username");
if (user=="Alfred"){
//Path A;
}
if (user=="other"){
//Path B;
}