This is a migrated thread and some comments may be shown as answers.

Add custom fields

5 Answers 259 Views
FileExplorer
This is a migrated thread and some comments may be shown as answers.
Adam
Top achievements
Rank 2
Adam asked on 16 Sep 2009, 11:55 PM
I see that I can add custom fields, and following an example from the forums, I have added a "Title" and "Description" input fields to my upload form.  But not sure what to do now.  How to I get the values of the Title and Description fields into the arguments array of the StoreFile() method?

protected void RadFileExplorer2_ItemCommand(object sender, Telerik.Web.UI.RadFileExplorerEventArgs e)  
        {  
            if (e.Command == "UploadFile")  
            {  
                RadFileExplorer explorer = sender as RadFileExplorer;  
                RadUpload upload = explorer.Upload;  
 
                //e.Path holds the file path  
                string name = e.Path.Split(new char[] { '/' }).Last(); // get the filename including extension ;  
 
                foreach (UploadedFile uploadedFile in upload.UploadedFiles)  
                {  
                    if (name.Equals(uploadedFile.GetName()))  
                    {  
                        string fileName = uploadedFile.GetName();  
                        string title = uploadedFile.GetFieldValue("Title");  
                        string description = uploadedFile.GetFieldValue("Desc");  
 
                        // ********** What do I do now? ***************//  
                        break;  
                    }  
 
                }  
            }  
        } 

From my custom FileBrowserContentProvider:

public override string StoreFile(Telerik.Web.UI.UploadedFile file, string path, string name, params string[] arguments)  
        {  
            int fileLength = Convert.ToInt32(file.InputStream.Length);  
            byte[] content = new byte[fileLength];  
            file.InputStream.Read(content, 0, fileLength);  
            string fullPath = CombinePath(path, name);  
 
            if (!Object.Equals(DataServer.GetItemRow(fullPath), null))  
            {  
                DataServer.ReplaceItemContent(fullPath, content);  
            }  
            else 
            {  
                string title; string description;  
                try 
                {  
                    title = arguments[0];  
                    description = arguments[1];  
                      
                }  
                catch (IndexOutOfRangeException)  
                {  
                    DataServer.CreateItem(name, path, file.ContentType, false, fileLength, content);  
                    return string.Empty;  
                }  
                DataServer.CreateItem(name, path, file.ContentType, false, fileLength, content, title, description);  
            }  
            return string.Empty;  
        } 

5 Answers, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 22 Sep 2009, 10:01 AM
Hello Adam,

Your approach is not correct in this case. You need to build and add the custom fields (title and description) to a FileBrowserItem depending on a file/folder that is stored on the server. This needs to be done manually in the FileBrowserContentProvider when an FileBrowserItem is created. In the StoreFile function, however, you process a new file that is uploading from the client to the server. This file does not exists in the RadFileExplorer's items collection (it will be added later in the ResolveRootDirectoryAsTree or ResolveDirectory methods) and respectively it does not have title or description set.
The above explained is true for the ItemCommand handler when a file is uploaded.

I hope this helps.

Sincerely yours,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Matthew Mackay
Top achievements
Rank 1
answered on 22 May 2010, 12:48 AM
As part of building a custom file provider is it possible to add new fields? I want to use your control with my own data (not files from a hard drive) but relational data from a database... say a custom of mine wants to organize books... they want to have their own set of folders etc.. there would be no real files on any harddrive and I would need book information instead of filesize etc..

Thoughts?
0
Fiko
Telerik team
answered on 26 May 2010, 02:07 PM
Hi Matthew,

I believe that these links will be of help for you:

Sincerely yours,
Fiko
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Matthew Mackay
Top achievements
Rank 1
answered on 01 Jun 2010, 11:38 PM
Thanks for the quick response...

Here are the things I'm trying to do with Explorer

1) Add / remove context menus in different situations (files vs folders for example) (maybe that could be done client side)
2) Server side events on context menu's (I've been trying to figure that one out to no avail)
3) Fire client side events upon server side events such as Item_Command etc.. (ScriptManager.register script??? )  OR display some kind of message / popup when we cancel = true on a move for example...
Thanks..

4) What is the difference between FileBrowserContentProvider and FileSystemContentProvider

The example of adding a custom column (which I need to do) uses FileSystem and the example of custom content (from database) uses FileBrowser (I need to do both)

5) How do I get the grid (within the file explorer) to scroll left and right as I add more columns)

Thanks
0
Fiko
Telerik team
answered on 04 Jun 2010, 01:21 PM
Hello Matthew,

In reference to your questions:
  1. I recommend you to apply the suggested in this KB article in order to achieve the desired result.
  2. The server-side events of the Menus in RadFileExplorer are canceled internally in the RadFileExplorer's code and I recommend you to use this approach (the key is the ajaxRequest method described in more details in this help page) in order to call a server-side method by clicking a menu item.
  3. Yes, you can use ScriptManager.RegisterStartupScript in order to alert messages from the server-side to the client-side.
  4. FileBrowserContentProvider class is an abstract class and it is the base class for all content providers, that can be used with RadFileExplorer and RadEditor controls. FileSystemContentProvider is inherited from FileBrowserContentProvider class and it ships with RadControls as default provider - it is not an abstract class.
  5. You need to add this code in the Page_Load event in order to set the desired width (300px in the provided example) of he Grid embedded in RadFileExplorer and allow scrolling in the pane, which holds the grid:
    protected void Page_Load(object sender, EventArgs e)
    {
        RadPane paneGrid = RadFileExplorer1.FindControl("paneGrid") as RadPane;
        RadFileExplorer1.Grid.Width = System.Web.UI.WebControls.Unit.Pixel(300);
        paneGrid.Scrolling = SplitterPaneScrolling.X;
    }
I hope this helps.

Kind regards,
Fiko
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
FileExplorer
Asked by
Adam
Top achievements
Rank 2
Answers by
Fiko
Telerik team
Matthew Mackay
Top achievements
Rank 1
Share this question
or