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

Allow only exact filename

4 Answers 33 Views
Upload (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Kurt Kluth
Top achievements
Rank 1
Kurt Kluth asked on 14 Nov 2013, 10:25 PM
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

4 Answers, 1 is accepted

Sort by
0
Kurt Kluth
Top achievements
Rank 1
answered on 15 Nov 2013, 03:36 PM
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).
0
Accepted
Vessy
Telerik team
answered on 19 Nov 2013, 03:17 PM
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.
0
Kurt Kluth
Top achievements
Rank 1
answered on 19 Nov 2013, 05:45 PM
Thank you Veselina that worked perfectly and the link surely offered additional information that proved helpful.
0
Vessy
Telerik team
answered on 20 Nov 2013, 09:17 AM
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.
Tags
Upload (Obsolete)
Asked by
Kurt Kluth
Top achievements
Rank 1
Answers by
Kurt Kluth
Top achievements
Rank 1
Vessy
Telerik team
Share this question
or