Is it possible to upload images with a prefix in RadEditors ImageManager

2 posts, 0 answers
  1. attila somogyi
    attila somogyi avatar
    2 posts
    Member since:
    Dec 2009

    Posted 16 Jun 2012 Link to this post

    I want to identify images users upload to each individual user.

    fr'instance if UserA and UserB uploads images in the ImageManager, I want it so UserA and UserB when using the ImageManager only see's and can edit their own images and not everyone else's. The problem with allowing everyone to upload to a single folder, is everyone can edit/delete/overwrite other users images, and it becomes a management nightmare, fr'instance if I delete a article I also want to know the associated images to that article so I code that they get deleted too.

    I've got situations where there will be about 2000-3000 images for particular types of submissions , such as article submissions/ event submissions, ...etc. to create a single folder for each user and submission type may end up with 10 of thousands of folders, I just want a single folder for images for each submission type, eg. a single folder for all article submission images, a single folder for all events images and so on...

    What's supprising is the ImageManager SearchPatterns Property seems to work for ViewPaths and DeletePaths but doesn't work for UpLoadPaths, fr'instance:

    SearchPatterns="100_*."  - where the 100 is say my userId. In this case when I view the ImageManager it shows only those images
    that begin with "100_" (Which is really cool and exactly what I want)

    What I've had to do - fr'instance for article submissions is in my form I've added a simple FileUpLoad control that is first hidden, and disabled the ImageManager in RadEditor. The user enter's stuff in the editor and submits (postback), I stored the article data in the database which returns the new articleId, then I set the SearchPatterns property of the ImageManager to equal (articleId+ "_*.*) the user is shown the form again, now with the FileUpLoad control shown and the ImageManager enabled in the RadEditor along with a message on the form " you can now add images to this article" - of course the form will be in edit mode now, so the Submission from this point will be an update not an insert. Now the user can add images via the FileUpLoad where the code will rename the image to "articleId_TheImageFileName" and upload it to the Articles folder, once it does this the user will only see the images added for this article in the ImageManager and can now add them into the RadEditor's text area.

    Is there any way to prefix a image name for UploadPaths in the ImageManager?
  2. Dobromir
    Dobromir avatar
    1633 posts

    Posted 20 Jun 2012 Link to this post

    Hi Attila,

    If I understand you scenario correctly, you need to add a prefix to the name of the uploaded file according to the users / article ID.

    You can achieve this by subclassing FileSystemContentProvider (the default content provider) of the ImageManager dialog and override its StoreFile() method. A similar scenario is demonstrated in the following KB article:
    Giving the uploaded files unique names

    Also, you will need to extend this example to provide the prefix value, which I would suggest you to pass through a hidden field on the page or a session variable. Then you can access the Page object from the content provider class through the HttpContext class, e.g.:
    Page _pageContainsRadFileExplorer = HttpContext.Current.Handler as Page;

    More detailed information regarding the FileBrowserContentProvider is available in the following help article:
    Using custom FileBrowserContentProvider

    On a side note, using wildcards for SearchPatterns property is not fully supported by the FileBrowser dialogs, and as it might work correctly for listing the items it may cause some unexpected behaviors. If you want to filter the listed items using the approach provided in this live demo.

    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top