Allow Any type of file in upload field

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
kirondedshem
User
Posts: 642

Allow Any type of file in upload field

Post by kirondedshem »

I have a field called attachment_file which i set as an upload field with view tag set to image. AM uploading into a given folder and saving the file name here. during row_inserting i can then do some validations on the file like i can know its extension etc which also works fine

When uploading a file which is one of the predefined allowed types like png,xls it works fine.

BUT i want users to be able to upload any type of file into this,. And i can not go adding all possible file types into the ASP.NET settings->file upload->allowed file type or in idvanced settinngs.

SO i want at runtime to be able to allow a user to browse and attach all files ie (.). AM doing it as below

// Page Load event
public override void Page_Render() {

            ////Log("Page Render");

            attachment_file.UploadAllowedFileExtensions = "*";

        }

When i inspect the browser i see it cange like <input name="fx_x_attachment_file" id="fx_x_attachment_file" value="*" type="hidden">

BUt it still wont allow if i browse a file of type like .mp3 etc.


Webmaster
User
Posts: 9427

Post by Webmaster »

Please clear the [ASP.NET] -> [General Options] -> [File Upload] -> [Allowed file types] setting (i.e. set to empty) and try again.


kirondedshem
User
Posts: 642

Post by kirondedshem »

thank it works, but can i also do it at runtime


Webmaster
User
Posts: 9427

Post by Webmaster »

To change the upload file types dynamically for a field, use the field level property <Field>.UploadAllowedFileExtensions.


kirondedshem
User
Posts: 642

Post by kirondedshem »

To change the upload file types dynamically for a field, use the field level property <Field>.UploadAllowedFileExtensions.
I know this and ive been using it, what is meant is

How can i (Please clear the [ASP.NET] -> [General Options] -> [File Upload] -> [Allowed file types] setting (i.e. set to empty)) at run time, without needing to change it in the whole project, I want to do this at some server event if possible


Webmaster
User
Posts: 9427

Post by Webmaster »

To change project level config you can use Class_Init server event, see Server Events and Client Scripts in the help file.


Post Reply