Saturday, December 21, 2013

Error : Upload File more than 30 MB in asp.net 

By default, IIS7 limits file upload to 30MB. Oddly, it returns a 404 error if someone uploads something larger than 30MB.

The docs from Microsoft are a little confusing on this, so I thought I would try to clarify. According to the following article, you can "Remove the maxAllowedContentLength property." from the applicationhost.config file in IIS7 to lift the 30MB limit. However, in my case, this property was never in the file to begin with.

http://support.microsoft.com/kb/942074/ So, my assumption on this is that the 30MB limit is somewhere internal to IIS7. The article also doesn't say where to ADD the entry requestLimits node if it isn't already there. Luckily, there is an alternate solution that can be enabled at the site level rather than server-wide.

If you add the above code to the web.config file for your site, you can control the maximum upload size for your site. In many cases, the system.webServer node will already be in the file, so just add the security node within that.


Note that the maxAllowedContentLength is in BYTES not kilobytes. You may also need to restart your Web site (not the whole server) to enable the setting. In case you are curious, why would I want people to upload files larger than 30MB? We were working on a video conversion script that allows people to upload large MOV files and converts them to FLV.

I hope this article will be very helpful to all. Thanks for reading this article.

“Keep reading and share the knowledge”  
“Grow more trees to save the Earth”
Split Function

In SQL Server there is no in-built split function. But we could create our own Split function and use.

Following is the script for Split function.
CREATE FUNCTION [dbo].[SPLIT] 
(
    @String NVARCHAR(MAX), --String need to be Split
    @Delimiter CHAR(1), --Demiliter
    @Index integer --Index of the Splited String
)
RETURNS VARCHAR(200)
AS
BEGIN
      -- Declare the return variable here
      DECLARE  @Start INT,  @End INT ,  @Count int,  @Value varchar(500)

      -- Add the T-SQL statements to compute the return value here
      SELECT  @Start = 1,  @End = CHARINDEX(@Delimiter,  @String)
      SET  @Count =1
      WHILE  @Start < LEN( @String) + 1 BEGIN
        IF  @End = 
            SET  @End = LEN( @String) + 1
      
        IF  @Count = @Index         
        set  @Value = (SUBSTRING( @String,  @Start,  @End -  @Start))        
        SET  @Start =  @End + 1
        SET  @End = CHARINDEX(@delimiter,  @String,  @Start)
        SET  @Count =  @Count + 1
      END

      -- Return the result of the function
      RETURN  @Value


END

Function will take following arguments

1. String: The string need to be split.

2. Delimiter: delimiter used to split the string.

3. Index: which index of value to be returned.

Example:


 I hope this article will be very helpful to all. Thanks for reading this article.

“Keep reading and share the knowledge”  
“Grow more trees to save the Earth”