Hi,
Is there a way to obtain the name of the currently selected file in codebehind? Thanks.
Karl WIlkens
9/18/2008 2:42 AM
I would purchase this control today if it was easy to do get the selected file. I need the equivalent of a file dialog box... upload, delete, rename, etc., plus select a file. This control does everything except make it simple to select a file. I hacked around in the javascript and figured it how to get the selected value, but it's a clunky solution.
Excellent control unless you just need to tell the server the currently selected file.
Jeff
10/16/2008 2:32 PM
Update... I bought it anyway... I really like the control and figured out a way to get the selected file... here's how:
1. Open the filevista.js file.
2. Add this javascript function (note - this uses JQuery, so make sure that's on your page).
function whenSelected(rootFolder,file,rootFolderID)
{
if (file.indexOf(".") < 1) file = '';
$( "input[staticID=txtPickedFile]" ).val(rootFolder + '\\' + file);
$( "input[staticID=txtRootFolderID]" ).val(rootFolderID);
}
2. I added this to the end of the onSelectionComplete(e) function in the filevista.js file:
whenSelected(currentFolder.fullPath, grid.getSelectedFirstRow().cells[nameColumn.index],currentFolder.rootFolderID);
3. Next, add the target of the selected file as textboxes in the ASP page that calls the FileVistaControl:
<asp:TextBox ID="txtHiddenPicked" style="display:none" runat="server"
staticID="txtPickedFile" ></asp:TextBox>
<asp:TextBox ID="txtPicked" runat="server" Width="500px"
staticID="txtPickedFile" ReadOnly="True"></asp:TextBox>
Note that the staticID value is so JQuery can reliably find the target field... ASP can mung the ID and Name values.
4. Finally, here's how to retrieve the target file after a postback:
if (IsPostBack)
{
txtPicked.Text = txtHiddenPicked.Text;
FileVistaRootFolder rootFolder = FileVistaControl.SessionRootFolders[Convert.ToInt32(txtRootFolderID.Text)];
m_selectedFile = rootFolder.PhysicalPath;
if (!m_selectedFile.EndsWith("\\")) m_selectedFile += "\\";
m_selectedFile += txtHiddenPicked.Text.Substring(txtHiddenPicked.Text.IndexOf("\\") + 1);
}
This works good... Hopefully future versions of the control (which is excellent, otherwise) will expose this by default.
Regards - Jeff
Jeff
11/12/2008 10:13 AM
Hi Jeff,
Thanks for your post. It seems you implemented your solution well according to the information in
File reference from component.
We plan to add a server-side event for file selection in future versions.
Cem Alacayir
11/17/2008 5:14 AM
FYI - This implementation does not allow directory values to be passed to the server, only file names. Remove
'if (file.indexOf(".") < 1) file = ''; '
From the function you add in filevista.js and it will pass directory names as well.
Great solution though, thanks Jeff :)
andy
12/11/2008 1:06 AM