Click here to Skip to main content
15,896,726 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: publish a web on server Pin
caradri8-Mar-16 0:04
caradri8-Mar-16 0:04 
QuestionRegarding different type of authentications in asp.net Pin
Tridip Bhattacharjee7-Mar-16 1:16
professionalTridip Bhattacharjee7-Mar-16 1:16 
AnswerRe: Regarding different type of authentications in asp.net Pin
Nathan Minier7-Mar-16 2:54
professionalNathan Minier7-Mar-16 2:54 
QuestionHow to show a Grid into modal window Pin
luismalpizar6-Mar-16 18:04
luismalpizar6-Mar-16 18:04 
QuestionWindows Client for web portal Pin
ashu20013-Mar-16 23:21
ashu20013-Mar-16 23:21 
AnswerRe: Windows Client for web portal Pin
Afzaal Ahmad Zeeshan7-Mar-16 5:19
professionalAfzaal Ahmad Zeeshan7-Mar-16 5:19 
GeneralRe: Windows Client for web portal Pin
ashu20018-Mar-16 16:53
ashu20018-Mar-16 16:53 
Questionfile upload file size limit Pin
indian1433-Mar-16 8:31
indian1433-Mar-16 8:31 
Hi,

I am using File Upload and I am limiting the file size limit in the Web config, when user uploads the exceeding limit the page is giving error message file size limit exceeds. Is there any way I can stop user from uploading the file more than the limit in first place. Because this error is coming after user selects the file and tries to save the page. But before that is user is stopped and said he is exceeding the limit that's nice either from the front client script or sever side code. Thanks in advance. I have used all the below code using client scripting and none of them returning file size.

Here is the code
function CheckImageTypeAndSizeEdit() {
    //var aspFileUpload = document.getElementById("fileUploadCurriculumVitaeEdit");
    //var errorLabel = document.getElementById("lbl_uploadMessageEdit");
    $("#<%=lbl_uploadFilePathFullEdit.ClientID %>").text('No file chosen');

    var fileName = $('input[type=file]').val();
    var fileSize; //errorLabel.innerHTML = "";

    var ext = fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase();

    if (!(ext == "docx" || ext == "doc" || ext == "pdf")) {
        alert("Invalid file type, must select a *.doc, *.docx, or *.pdf file.");
        $("#<%=lbl_uploadFilePathFullEdit.ClientID %>").text("");
        $('input[type=file]').val('');
        $("#<%=lbl_uploadFilePathFullEdit.ClientID %>").text('No file chosen');
        return false;
    }
    else {
        $("#<%=lbl_uploadMessageEdit.ClientID %>").text("");
        $("#<%=lbl_uploadFilePathFullEdit.ClientID %>").text($('input[type=file]').val());
    }

    try {
        fileSize = aspFileUpload.files[0].size; // Size returned in bytes.
        alert(fileSize);
    } catch (e) {
        try
        {
            var objFSO = new ActiveXObject("Scripting.FileSystemObject");
            var e = objFSO.getFile(fileName);
            fileSize = e.size;
            alert(fileSize);
        }
        catch (a)
        {
            /// get list of files
            var file_list = e.target.files;

            /// go through the list of files
            for (var i = 0, file; file = file_list[i]; i++) {

                var sFileName = file.name;
                var sFileExtension = sFileName.split('.')[sFileName.split('.').length - 1].toLowerCase();
                var iFileSize = file.size;
                var iConvert = (file.size / 1048576).toFixed(2);

                /// OR together the accepted extensions and NOT it. Then OR the size cond.
                /// It's easier to see this way, but just a suggestion - no requirement.
                if (!(sFileExtension === "pdf" ||
                      sFileExtension === "doc" ||
                      sFileExtension === "docx") || iFileSize > 10485760) { /// 10 mb
                    txt = "File type : " + sFileExtension + "\n\n";
                    txt += "Size: " + iConvert + " MB \n\n";
                    txt += "Please make sure your file is in pdf or doc format and less than 10 MB.\n\n";
                    alert(txt);
                }
            }
        }

    }

    //if (fileSize == -1) {
    //    $("#lbl_uploadMessageEdit").val("Couldn't load doc file size.  Please try to save again.");
    //    $('input[type=file]').val() = "No file chosen";
    //    return false;
    //}
    //else if (fileSize <= 2097152) {
    //    $("#lbl_uploadMessageEdit").val(fileName);
    //    return true;
    //}
    //else {$("#lbl_uploadMessageEdit").val("File is too large, must select file under 20 Mb. File  Size: " + fileSize.toFixed(1).toString() + " Mb");
    //    $('input[type=file]').val() = "No file chosen";
    //    return false;
    //}
}
Thanks,

Abdul Aleem

"There is already enough hatred in the world lets spread love, compassion and affection."

AnswerRe: file upload file size limit Pin
Wombaticus6-Mar-16 7:37
Wombaticus6-Mar-16 7:37 
GeneralRe: file upload file size limit Pin
indian1436-Mar-16 16:48
indian1436-Mar-16 16:48 
SuggestionRe: file upload file size limit Pin
Richard Deeming6-Mar-16 23:04
mveRichard Deeming6-Mar-16 23:04 
GeneralRe: file upload file size limit Pin
Wombaticus6-Mar-16 23:15
Wombaticus6-Mar-16 23:15 
QuestionHow to learn C# in Asp.net Mvc Pin
Member 122016262-Mar-16 0:08
Member 122016262-Mar-16 0:08 
AnswerRe: How to learn C# in Asp.net Mvc Pin
Richard MacCutchan2-Mar-16 1:06
mveRichard MacCutchan2-Mar-16 1:06 
GeneralRe: How to learn C# in Asp.net Mvc Pin
Member 122016262-Mar-16 1:26
Member 122016262-Mar-16 1:26 
GeneralRe: How to learn C# in Asp.net Mvc Pin
Richard MacCutchan2-Mar-16 1:49
mveRichard MacCutchan2-Mar-16 1:49 
AnswerRe: How to learn C# in Asp.net Mvc Pin
Manas_Kumar2-Mar-16 18:53
professionalManas_Kumar2-Mar-16 18:53 
AnswerRe: How to learn C# in Asp.net Mvc Pin
Frank Kerrigan4-Mar-16 3:58
Frank Kerrigan4-Mar-16 3:58 
AnswerRe: How to learn C# in Asp.net Mvc Pin
aarif moh shaikh10-Mar-16 20:50
professionalaarif moh shaikh10-Mar-16 20:50 
QuestionVisual Studio 2015 and Metro-UI Pin
xiecsuk29-Feb-16 22:59
xiecsuk29-Feb-16 22:59 
QuestionOpening word/pdf document in another window Pin
indian14329-Feb-16 15:39
indian14329-Feb-16 15:39 
AnswerRe: Opening word/pdf document in another window Pin
Richard MacCutchan29-Feb-16 22:04
mveRichard MacCutchan29-Feb-16 22:04 
GeneralRe: Opening word/pdf document in another window Pin
indian14329-Feb-16 22:26
indian14329-Feb-16 22:26 
GeneralRe: Opening word/pdf document in another window Pin
Blikkies29-Feb-16 23:01
professionalBlikkies29-Feb-16 23:01 
GeneralRe: Opening word/pdf document in another window Pin
indian1431-Mar-16 6:06
indian1431-Mar-16 6:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.