These forums are read-only and considered to be an archive. Please use the new Community for future interaction and posts.

Sever side code to determine selected files

Hi,

Please let me know if there is a way to do it?

Thank You

Sergioza 11/4/2008 9:15 AM
I did it by modifying the filevista.js file a little bit:

1. I added this javascript function (note - this uses JQuery).

  
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. Finally, I added the target of the selected file as textboxes in my 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.

This works good... Hopefully future versions of the control (which is excellent) will expose this by default.

Regards - Jeff
Jeff 11/12/2008 10:05 AM
Thank You Jeff,

I'm not extremely comfortable wuth Javascript.

Do you know what's the way to obtain names of multiple, not one
selected file?

Thank You Again
Sergioza 11/14/2008 10:33 AM
This subject was discussed in File reference from component.

Note that in Jeff's code:


whenSelected(currentFolder.fullPath, grid.getSelectedFirstRow().cells[nameColumn.index],currentFolder.rootFolderID);


He gets only the first selected item with grid.getSelectedFirstRow().cells[nameColumn.index]

You can obtain all the selected items with this loop


for (var key in grid.selectedRows) 
    grid.selectedRows[key].cells[nameColumn.index]; 


So you can modify Jeff's code in this way:


var selectedItems = "";

for (var key in grid.selectedRows) 
    selectedItems += grid.selectedRows[key].cells[nameColumn.index] + "," ; 

whenSelected(currentFolder.fullPath, selectedItems,currentFolder.rootFolderID);


Note that we build selectedItems string by combining all the selected items with comma ",". So on the server side, you will need to split this string to have an array of selected items. You can use string.Split method with RemoveEmptyEntries option to build the array:


string[] itemsArray = postedString.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
Cem Alacayir 11/17/2008 5:32 AM