Allow only exact filename

Thread is closed for posting
5 posts, 1 answers
  1. Kurt Kluth
    Kurt Kluth avatar
    144 posts
    Member since:
    Oct 2009

    Posted 14 Nov 2013 Link to this post

    Using the FileUpload control and curious if I can restrict the filename to be a certain name?
    Basically ###.pdf, where I will know the number of the file they should be uploading.  Also when the control pops up for the "Upload" any way of limiting it to only 1 "Select" box, No "Add"

                <telerik:RadFileExplorer runat="server" ID="FileExplorer1" Width="520px" Height="300px">
                        <Configuration ViewPaths="~/PDF/ECPay" UploadPaths="~/PDF/ECPay"
                            DeletePaths="~/PDF/ECPay" AllowFileExtensionRename="True"></Configuration>
                </telerik:RadFileExplorer>
     
    Code Behind
        Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            Dim iASI_Num As Integer = Request("ASI_Num")
     
            'set properties according to configuration panel
            FileExplorer1.Configuration.SearchPatterns = New String() {"*.pdf"}
            FileExplorer1.VisibleControls = GetVisibleControls()
            FileExplorer1.EnableOpenFile = True
            FileExplorer1.DisplayUpFolderItem = False
            FileExplorer1.AllowPaging = False
            FileExplorer1.EnableCreateNewFolder = False
            FileExplorer1.Configuration.AllowFileExtensionRename = False
     
            If (FileExplorer1.VisibleControls And Telerik.Web.UI.FileExplorer.FileExplorerControls.Grid) = 0 Then
                FileExplorer1.ExplorerMode = Telerik.Web.UI.FileExplorer.FileExplorerMode.Thumbnails
            End If
     
            If (FileExplorer1.VisibleControls And Telerik.Web.UI.FileExplorer.FileExplorerControls.ListView) = 0 Then
                FileExplorer1.ExplorerMode = Telerik.Web.UI.FileExplorer.FileExplorerMode.[Default]
            End If
     
            FileExplorer1.Configuration.UploadPaths = New String() {"~/PDF/ECPay"}
            FileExplorer1.Configuration.DeletePaths = New String() {"~/PDF/ECPay"}
        End Sub
     
        Protected Function GetVisibleControls() As Telerik.Web.UI.FileExplorer.FileExplorerControls
            Dim explorerControls As Telerik.Web.UI.FileExplorer.FileExplorerControls = 0
     
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.AddressBox
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.Grid
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.ListView
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.Toolbar
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.TreeView
            explorerControls = explorerControls Or Telerik.Web.UI.FileExplorer.FileExplorerControls.ContextMenus
     
     
            Return explorerControls
        End Function
    End Class
  2. Kurt Kluth
    Kurt Kluth avatar
    144 posts
    Member since:
    Oct 2009

    Posted 15 Nov 2013 Link to this post

    After thinking about this it would just be easier if we renamed the file they uploaded.  How can I go about doing that?  If they upload ABC.pdf, I would rename it to 123.pdf (or whatever the number would be)

    What we have numbers for our clients and what I want visible within the "explorer" window is their only file.  Any way of limiting what they see without setting up a folder for each client.  All the files will live in one directory but I would like only 123.pdf file to show but if they were looking at client #456, it would show only 456.pdf (if exists).
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Answer
    Vessy
    Admin
    Vessy avatar
    1388 posts

    Posted 19 Nov 2013 Link to this post

    Hello Kurt,

    You can configure the FileExplorer's nested upload control to allow uploading only of one file in a similar way:
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        RadFileExplorer1.Upload.InitialFileInputsCount = 1
        RadFileExplorer1.Upload.MaxFileInputsCount = 1
    End Sub

    In order to change the name of the uploaded file you will need to subclass the built-in FileBrowserContentProvider, overriding its StoreFile method:
    Public Overrides Function StoreFile(file As Telerik.Web.UI.UploadedFile, path As String, name As String, ParamArray arguments As String()) As String
        Dim extension As String = name.Substring(name.LastIndexOf("."))
        name = "123" + extension 'put here your logic for getting the client id
     
        Return MyBase.StoreFile(file, path, name)
    End Function

    I hope this helps.

    Regards,
    Veselina Raykova
    Telerik
    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 the blog feed now.
  5. Kurt Kluth
    Kurt Kluth avatar
    144 posts
    Member since:
    Oct 2009

    Posted 19 Nov 2013 Link to this post

    Thank you Veselina that worked perfectly and the link surely offered additional information that proved helpful.
  6. Vessy
    Admin
    Vessy avatar
    1388 posts

    Posted 20 Nov 2013 Link to this post

    Hello Kurt,

    I am glad the provided information was useful for you. Feel free to contact us in case we could be of any further assistance.

    Regards,
    Veselina Raykova
    Telerik
    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 the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017