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

ASP.NET

 
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 
AnswerRe: file upload file size limit Pin
Wombaticus6-Mar-16 7:37
Wombaticus6-Mar-16 7:37 
Yes, this can be tricky - it took me years to come up with a decent solution. Client side, here's a .js function I cribbed together from various things I found here on CP over the years - attach it to the onchange event of your Fileupload control
JavaScript
function checkFile(what, mb, iLen, types) {
   // what  : always =this in calling function
   // mb    : max file size allowed in MB
   // iLen  : max length of filename allowed (excluding the extension); 0 means don't test for length
   // types : comma-delimited string of allowed file extensions
   // eg, call with onchange="checkFile(this,3,50,'doc,docx,pdf')"
   var msg = '';
   var source = what.value;
   var i = source.lastIndexOf('\');
   var j = source.lastIndexOf('.');
   var fName = source.substring(i + 1, j);
   var ext = source.substring(source.lastIndexOf(".") + 1, source.length).toLowerCase();
   var exts = types.split(',');
   var fileTypeAllowed = false;
   for (var k = 0; k < exts.length; k++) {
      if (ext == exts[k]) {
         fileTypeAllowed = true;
         break;
      }
   }
   if (fileTypeAllowed == true) {
      var regex = /^[A-Za-z0-9_ -]{1,1024}$/;
      if (!regex.test(fName)) {
         msg = 'The file name contains illegal characters\n  Please re-name the file using only alphanumeric characters, hyphens, spaces and underscores\n';
      }
   } else {
      msg = 'Please upload files of the following types only:\n  ' + types + '\n';
   }
   if ((iLen > 0) && (fName.length > iLen)) {
      msg += 'The file name is too long\n  Please restrict it to ' + iLen.toString() + ' characters.\n';
   }
   var fileSize = what.files[0].size;
   var iMax = mb * 1024 * 1000;
   if (!((fileSize > 0) && (fileSize <= iMax))) {
      msg += "The file size should be greater than 0 and less than " + mb.toString() + "MB\n";
   }
   if (!(msg == '')) { what.value = null; alert(msg + '\n' + fName + '.' + ext); }
}
Server side, you can add this to the Application_BeginRequest event in global.asax (VB code) - after adjusting the number of bytes according to what you want
VB
Dim sUrl As String = Request.Url.ToString.ToLower
If Request.ContentLength > 4096000 Then 
    Response.Redirect([full path to some nice error page])
End If
Hope this helps.
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 
GeneralRe: Opening word/pdf document in another window Pin
indian1431-Mar-16 6:08
indian1431-Mar-16 6:08 

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.