Showing posts with label Angular. Show all posts
Showing posts with label Angular. Show all posts

Thursday, April 11, 2019

ASP.Net MVC file downloader to download file at user machine

Here is a simple source what will download file in user machine on a Asp.Net web application.
This can be implement in Angular application also.

Step 1 - new action in asp.net MVC controller


Byte[] dashboardfileBytes = File.ReadAllBytes(Full File LOCATION);

response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new ByteArrayContent(updatefilebytes);
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = repsourceFileInfo[0].Name;
response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/xlsm");


Step 2 - download from client side

download is very simple, you have a add a <a> tag and in href property you needs to send Asp.Net MVC url for the action you created above

ex:
<a hreff="mycontroller\FileDownloadAction" >download File </a>

the same logic you can implement in angular, instead of calling asp.net MVC controoler\action url, you can use WebAPI url.

Tuesday, March 19, 2019

Display <div> content in column wise

Output






Here explain a way to display multiple <div> in column wise. To achieve this, we required one Parent <div>, and parent div contains multiple child <div>, we list child <div> in column wise.

To achieve this we just need a style like below.

<style>

 

* {

           box-sizing : border-box ;
    }

 

/* Create equal columns that floats next to each other */
.column{

                        float:left ;
          width:50%;

                        padding : 10px;

}

 

/* Clear floats after the columns */

.row:after{

                 content : "";

                        display : table;

                        clear : both;

}

</style>


hope style is straight forward, width in style-class .column and display in style-class .row:after is crucial here. Width property defining number of column to be displayed.

 

 

HTML
you should required one parent and multiple child <div> tags. Below is parent should look like below. Parent should refer style-class "row

 

<divname="parent"class="row"style="width:100%;">


Child should refer style-class "column" and put your content under the <div> tag 

 

<divname="child"class="column"style= "background: cornflowerblue" >

 

Once complete above, your child <div> will list in two column. If you decrease the width property of style-class .column to 30%, then <div> will list in 3 column, like that you could reduce the width to list desired level of columns.


HTML should be like below.

 

<divname="parent"style="width: 100%;"class="row">

           <divname="child"class="column"style= "background: cornflowerblue" >

                     <divname="childcontent">

                               My Content 1

                     </div>

           </div>

            

           <divname="child"class="column"style= "background: cornflowerblue" >

                     <divname="childcontent">

                               My Content 2

                     </div>

           </div>

 

           <divname="child"class="column"style= "background: cornflowerblue" >

                     <divname="childcontent">

                               My Content 3

                     </div>

           </div>

 

           <divname="child"class="column"style= "background: cornflowerblue" >

                     <divname="childcontent">

                               My Content 4

                     </div>

           </div>

</div>

 

Output