Monday, 26 September 2016

Download / Upload large files in C# Asp.Net

 
Download / Upload large files in C# Asp.Net
                               In web application download and upload are very common . Earlier the file was small .500 kb text file , 500 kb image file ot doc file of maximum 1 mb . Now with enhancement of technology , normal images getting high definition images , normal video files to high definition videos , the size of this files are long . I can remember in 1997 , we use floppy disk to store information , which maximum capacity was 1.44 Mb.Now days , a still photo comes with more than 1 Mb . However , as developer we have to handle the situation with demand . Now I am showing , how we will upload & down load Large files

Upload large file
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DownloadFile.aspx.cs" Inherits="DownloadFile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <INPUT type=file id=File1 name=File1 runat="server" >
    <asp:Button ID="btnUploadFile" runat="server" onclick="btnUploadFile_Click"
        Text="Upload File" />
    </form>
</body>
</html>
protected void btnUploadFile_Click(object sender, EventArgs e)
    {
        string FileName = "AAOHN Headquarters - August 10th Webinar Video.wmv";
        string PathName = @"C:\\Users\\abanerjee\\Desktop\\download_large_files\\LargeFile\\" + FileName;
     
        string fn = System.IO.Path.GetFileName(File1.PostedFile.FileName);
        string SaveLocation = Server.MapPath("DownLoad") + "\\" + fn;
        try
        {
            File1.PostedFile.SaveAs(SaveLocation);
            Response.Write("The file has been uploaded.");
        }
        catch (Exception ex)
        {
            Response.Write("Error: " + ex.Message);
             
        }
    }
----------------------web.config-----------------------------------------------

xml version="1.0"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime
executionTimeout="90"
maxRequestLength="524288000"
useFullyQualifiedRedirectUrl="false"
minFreeThreads="8"
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
enableVersionHeader="true"
/>
  </system.web>
</configuration>

Upload larger file is similar to upload file , one change is there , you have to just change 
maxRequestLength value as per requirement , to handle  500 Mb files we have changes it to
524288000 .No other changes are required .




Download a larger file 500Mb/1GB/2GB
-------------------------------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DownloadFile.aspx.cs" Inherits="DownloadFile" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:Button ID="btnDownLoad" runat="server" onclick="btnDownLoad_Click"
            Text="Down Load" />
   
    </div>
   
    </form>
</body>
</html>

protected void btnDownLoad_Click(object sender, EventArgs e)
    {
       
        //here we have taken a sample file name and path
        string FileName = "myfilename.wmv";
        string PathName =  "c://MyFiles/"+FileName;
        
        //we are checking file exists or not 
        if (System.IO.File.Exists(PathName) == false)
        {
            return;
        }
        else
        {
            System.IO.Stream myStream = null;

            try
            {
                myStream =
                    new System.IO.FileStream
                        (path: PathName,
                        mode: System.IO.FileMode.Open,
                        share: System.IO.FileShare.Read,
                        access: System.IO.FileAccess.Read);
                //
                long lngFile = myStream.Length;
                long lngData = lngFile;
                Response.Buffer = false;
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);               
                Response.AddHeader("Content-Length", lngFile.ToString());
                // **************************************************
                //looping through the streaming length
                while (lngData > 0)
                {
                    if (Response.IsClientConnected)
                    {
                        // 8KB
                        int intBufferSize = 8 * 1024;

                        byte[] bytBuffers =
                            new System.Byte[intBufferSize];

                        int intTheBytesThatReallyHasBeenReadFromTheStream =
                            myStream.Read(buffer: bytBuffers, offset: 0, count: intBufferSize);

                        Response.OutputStream.Write
                            (buffer: bytBuffers, offset: 0,
                            count: intTheBytesThatReallyHasBeenReadFromTheStream);

                        Response.Flush();

                        lngData =
                            lngData - intTheBytesThatReallyHasBeenReadFromTheStream;
                    }
                    else
                    {
                        lngData = -1;
                    }
                }
            }
            catch { }
            finally
            {
                if (myStream != null)
                {
                    //Close the file.
                    myStream.Close();
                    myStream.Dispose();
                    myStream = null;
                }
                Response.Close();
            }
        }
    }





Friday, 23 September 2016

Bulk copy in Sql server & C#


Bulk copy in Sql server & C#
                  Bulycopy is an utility to copy data from source from destination for larger data . It can be text to Microsoft Sql server or Sql server to text file or text file to text file or sql server to sql server . This is and utility present in both Sql server and C#/Vb.net . Developer decides which way , he should use . Both bulk copy operation comes under transaction management . Bulk copy can be Single operation or Multiple operation .The simplest approach to performing a SQL Server bulk copy operation is to perform a single operation against a database , that is called Single operation , You can perform multiple bulk copy operations using a single instance of a SqlBulkCopy class , that is called Multiple operation . In this article we will see some simple example of bulkcopy . First we will see how to do with sql server.

Sql Server to text file :
--1. we are createing a table first
CREATE table tbl_bulkcopy
(
id    INT identity,
name  VARCHAR(50),
roll  INT
)
--insert data to the table
INSERT INTO tbl_bulkcopy(name,roll) VALUES('Ayan',20)
INSERT INTO tbl_bulkcopy(name,roll) VALUES('John',21)

--declare some use ful variable
DECLARE @fp             NVARCHAR(200)
DECLARE @fn             NVARCHAR(200)
DECLARE @sql            NVARCHAR(200)
DECLARE @opqry            NVARCHAR(200)

--set values of the variable
SELECT @fp ='C\copypath\'
SELECT @fn ='bulkcopy.txt'
SELECT @opqry='type '+@fp+@fn
---
---write the select query
SELECT @sql='SELECT name ,roll FROM tbl_bulkcopy'
---create the bulk copy script
SET @sql =  'bcp ' + '"' +  @sql + '"' +  '  queryout "' + @fp + @fn +'"   -c -q -C1252 -T '
--run the script in command shell
EXECUTE master..xp_cmdshell @sql
--
--to see the output of the file , please write the code
--or you can open the file directly
EXECUTE master..xp_cmdshell @opqry


Text file (.txt, csv) to Sql Server
--1. we are createing a table first
CREATE table tbl_bulkcopy
(
 id    INT identity,
[field1] VARCHAR(500),
[field2] VARCHAR(500),
[field3] VARCHAR(500),
)
--place the correct path of your file     
--you can specify field deliminator , row deliminator
--you can spcify error file also
BULK INSERT tbl_bulkcopy
FROM 'C:\dataloading\ex311316\outgoing\10_Group_Sub_Group.txt'
WITH
(
    FIRSTROW = 2,
    FIELDTERMINATOR = ',',  --CSV field delimiter
    ROWTERMINATOR = '\n',   --Use to shift the control to next row
    ERRORFILE = 'C:\dataloading\ex311316\outgoing\bulkcopy2p.txt',
    TABLOCK
)
EXECUTE master..xp_cmdshell @opqry
--
--
SELECT field1,field2,field3 FROM tbl_bulkcop

012 Weekend Tour Ambika Kalna

  Ambika Kalna  

                      Ambika Kalna is a small town in the district of West Bengal india .The town is located at the bank of Bhagirathi River and have a good history. Amika Kanlna is well know for 108 Shiva temple and Ambika kali temple , beside this you will see Rash Mach, Pratapeshaer temple , Lalji temple  ect.The town is named after the Goddess Kali , Ma Ambika.








108 Shiva Mandir : Here you will get 108 Shiva Temple in circular way . There are two circle , the outer circle contain 75 Shiva temple and the inner circle contain 35 Shiva temple . Each temple contain a idol of lord Shiva (Shiva Linga) , some of the are white and some are black .The place is under Archaeological survey of India .Well maintained and well decorate garden with green grass and flower tree .If you like to worship , you will get Bhamhin just siting by the side of the gate and ask him to assist you to worship . The temple are build on a platform , you have to climb 3 to 4 stairs to get on the platform.It is just 4Km away from Kalna station.You will get Risksaw /Auto to reach there .We hire a Ricksah , the cost was 20/-. This temple Known as Nava Kailash.The temple build by Bardhaman Maharaj Tej Chandra in year of 1809 .







                         One the other side of the rad of Nava Kailash , you will see a walled area , getting there you will get the most beautiful temple architecture of Bengal , Pratapeshaer temple,decorated with terracotta .This place also comes under Archaeological survey of India  and well decorated green garden , you can spend some time here ,. The temple was build on 1849 in Deul style.

                         By walking some step , you will get Rash Manch , a Bengali cultural,traditional festival dedicated on lord krisna.Other than this you will get Lalaji Temple and Krisnachandra Temple , Both have a good history.







How to Go : There are plenty of train from Howrah and Sealdah
                     Howrah –Katwa local :5.38AM,7.53AM,10.00AM
                     Sealdah –Katwah local:8.04AM,11:50AM

You should reach Ambika Kalna almost after 2 hrs by train.
You hire a Rckshaw or Auto and Getting around the town. We did the same , the Cost was 100/-.You can rive your won car also, the distance between Kolkata and Kalna around 90km.

Where to Stay :I did not find and good quality hotels to stay , however you can eat at Priyadarshini hotels .The hotel is just beside the main road ans driver to go there.


Thursday, 22 September 2016

006 Weekend Tour Ghatshila


Weekend trip Ghatshila

                         Ghatshila is a small town in the state of Jharkand . The town is located on the bank of Subarnarekha river . It is a popular place for weekend tour and famous for picnic during winter. The place is ideal for climate change and natural beauty all around the town. You can take a an evening walk on the bank of Subarnarekha river.



Place to see : Burudih lake is the main attraction of Ghatshila. other than Burudih lake , the other attraction are Subarnarekha river , Dharagiri falls , Galudih Dam ,Hindustan Copper Limite , Phuldungri Hill ,House of Bibhuti Bhusan Bandhapadya ect.

Burudih lake : Burudih lake is around 9 km away from the main town. The lake is surrounded by hills And lush of green around it .The scenic beauty of the Burudih Lake is marvelous .You can spend some time on the bank of the lake and can take some fresh  breath on the pure air.You will see the fisher man are fishing there .This spot is famous for picnic .Number of Picnic party come and enjoy picnic around the lake in the winter.




Dharagiri falls : You have to go another 5 km from Burudih lake to see Dharagiri falls .Road are not well build , traveling though this road is very tuff , but all around you , you will get green scenery and you may notice some innocent villager is passing by , most of the are Santal.You will meet some village over here while going toward the falls, but the thick forest and hills around create its own charm . Around 1.5km from Dharagiri falls , your Auto / Car will stop , you have to take any villager or younger person to guide you towards the falls.Mainly some small children of this area are ready to this work .We went in the month of May , we found a small water flow from the falls , but we cam to know that in the Monsoon , the flow become large and heavy.



Subarnarekha River : Subarnarekha means golden steak , though the river is not so deep , but it is the heart of the town . Picnic is also done in the bank of Subarnarekha mostly in the winter . Large grass and yellowish water , create a beautiful view of Subarnarekha .



Galudih  : Galudih , a barrage on Subarnarekha river is just few kilometer away .you can hire a taxi or Auto to visit Galudih . The Barrage is beautiful and you can spend some time on the barrage.

Next attraction is house of Bibhuti Bhusan Bandhapadya , the famous Bengali writer of “Pather pachali” ,”Araner Din Ratri” etc .The name of the house is “Gaurikunj” . The earlier house now renovated .Here you can see the several thing user by the writer . His books , tables , dress ect.

How to Reach : By Train from Howrah Ispat Express, Steel Express
By road , kolkata to Ghashila distance around 240 Km.You can drive you own car . There is no direct bus kolkata to Ghatshila.You will get bus from Kharagpur.

Where to Stay : There are few hotels in Ghatshila , hotel Akash, Hoter Shehalata ect. It is recommended to Book hotels before goin there, specially during the winter. There are some home stay also.

Wednesday, 21 September 2016

007 Weekend Tour Purulia

Weeken trip Purulia

                 Purulia a district of West Bengal ,India . A land of Bengali culture and tradition. Purulia was earlier known as “Manbhum City”. This district is famous for "chhau" dance , a cultural  and tradition dance of Bengal.



                                        
What to see :- The main attraction of purulia is Ayodha hill, chhau dance,Mayus hill , Pakhi hill ect.

Ayodha hill :  The hill is situated in between Jharkand and Purulia .The hill is full of dense forest with wild animals. While traveling toward Ayodha hill from purulia , you will see sugar cane field. Hut made of mud and beautifully decorated with natural color by the Santhal  people. In Ayodha hills there is a falls, locally called "Brahmani" falls. You have to get down by rocks to see the falls , while getting down the falls , you will notice a beautiful blue dam full of water , the blue water with lust of green around it. After getting down the steps of the rocks ,you with get Brahmani falls. Then you can go to visit Mayus hills, you have to go to the top of the Mayus hill by walkin , beautiful scenic beauty from the top of the hill. There are two Dam in Adoydha , upper Ayodha dam and Lower Ayodha Dam.This dam are actually nothing but hydro electric project.





The beautifull green Ayodha and in between this dam create a beautiful scenic beauty. You can also go to this dam , Broad road goes through the dam ,you can enjoy the beauty of the dam . Ajodhya is also ideal for trekking , a lot of people trek around it every year.

You can also go to Pakhi Pahar , a variety number of bird can be watch here.




Chhau dance is the famous attraction of purulia .A village name “Charida” is famous in the world , where mask of "chhcu" dance is prepared.While walking though the road in charida , both side you will notice small house ,if you notce carefully , you will notice ,each house , chhau artist are making mask of chhau dance . Chhau mash are made of wet paper , mud , decorate after .You can also purchase mask from from them . Some of the artist  national level award winner .


Purulia Science Museum is another attraction of purulia . Try to visit Purulia Science Museum and it is very close to purulia main city. You can take a Ricksaw to go there.










Where to stay :There are a lot of moderate and elite hotels in Purulia.You can do your booking from kolkata also.We stayed at “Sankat Mochan” hotel.The room rent was 700/- and food quality and hotels staff behavior was very attractive.








How to Reach :Howrah Junction to Purulia Junction  Train
           Howrah - Purulia Express Daily
           Lalmati Express Tu & Sa Dep. : 08:30
Bus root are also there ,
Purulia-Esplande Bus are there for SBSTC and private busese are also availabe.

When to Visit : Any time in Year is ideal to visit purulia , but I will suggest December to January


While returning , you can go to Joychandi Pahar , a raiway station is named after the devi "joy chandi" . At the top of the hill ,a Temple of lord Joychandi is there , you can visit there and worship Devi Joychandi.




বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...