Category Archives: ASP .Net

ASP .Net, VB and C#

Upload & Download File to Azure Blob Storage Asynchronously and Cancel Async With VB .Net


Asynchronous technique becomes important when dealing with cloud resources or accessing object in long distance network route.
Latency could blocking the application UI for sometimes if there are any big resources processed synchronously.

Microsoft Windows Azure Storage is one of best options to store Blob, File, Queue, Document Table and also SQL databases.
Other well known and could considered as best cloud storage options are Amazon S3, Google but this post will be focused on Azure since the source code is built for Azure storage.

The source code in this post is available for download at below url:
WinCloudAsyncAwait SourceCode

The demonstration application is a Visual Basic .Net WinForm. This app upload and download image file from/to Azure Blob storage asynchronously.
It also has Cancel to Async thread and List of uploaded files. Below is the Form’s design

Continue reading

Advertisements

C# Async Await Implementation Examples on Console App, Win Form and Asp.Net Web App

This post gives examples to use async and await in order to process something asynchronously.

Examples will be presented as Console App, Win Form and Asp.Net Web App.

Taking a definition reference of Async & Await from https://msdn.microsoft.com/en-us/library/hh191443(v=vs.120).aspx :
You can avoid performance bottlenecks and enhance the overall responsiveness of your application by using asynchronous programming. However, traditional techniques for writing asynchronous applications can be complicated, making them difficult to write, debug, and maintain.

Visual Studio 2012 introduces a simplified approach, async programming, that leverages asynchronous support in the .NET Framework 4.5 and the Windows Runtime.
The compiler does the difficult work that the developer used to do, and your application retains a logical structure that resembles synchronous code.
As a result, you get all the advantages of asynchronous programming with a fraction of the effort.

Continue reading

Basic Understanding of Using JQuery DataTable Server Side And Asp.Net

Intro

JQuery DataTable definition taken from https://datatables.net/ that DataTables is a plug-in for the jQuery Javascript library.
It is a highly flexible tool, based upon the foundations of progressive enhancement, and will add advanced interaction controls to any HTML table.

Common example of basic usage on JQuery DataTable is not Server side processing. You can imagine it is a data collection method that retrieve all data represent as Json string and stored in the DataTable.
So paging, searching, ordering are fully client side processing. This is handy if the data is not large enough.

On the other hand, Server Side processing in JQuery DataTable take data partially based on user request.
Pagination queries data in between start & end records in that page.
Searching will search data on fields usualy with Sql Like also Ordering will do Sql Order by.
All data taken from database server dynamically.

However, this server side processing could be confusing for someone who just exploring JQuery DataTable.
So this post explains jQuery DataTable server side basic understanding with a simple example.
We will use Newtonsoft component to convert class object to Json string. You need to install it using Nuget package manager.

Example

First of all, we need to include CSS, jQuery and jQuery DataTable javascript in aspx file.

<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" />
    <script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.js"></script>
    <script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>

And then the html table as DataTable. This table has id example

<table id="example" class="display" cellspacing="0" width="100%">
	<thead>
		<tr>
			<th>Full Name</th>
			<th>Phone Number</th>
			 <th>Fax Number</th>
			<th>Email Address</th>
		</tr>
	</thead>

	</table>

Continue reading

Upload file to Azure Cloud Storage Via Asp.Net Web App

windows_azure

Intro

Micrososft WindowsAzure is a rock solid Cloud platform that enables you automatically scales in/out your web application.
Not only scaling capabilites but also storing your files whether they are big or small in Azure Cloud Storage makes your mind free from conserning your own reliable storage on premise.
I give you basic example how to upload a file to Azure Cloud Storage via Web App using Asp.Net C#. Also to provide a link for user to download that uploaded file.

Create Storage Account or Use Local Development Storage

If you are still under development and run the web app under local PC/Laptop then you can use Development Storage.
Install necessary Azure SDK using Visual Studio 2013 or 2015 or Microsoft Web Platform Installer. After the installation done you should have Compute Emulator and Storage Emulator.
The storage emulator must be started properly before hand in order to run your Storage application in your local environment.

To access your storage you must supply Storage Connection String. Since we are using local environment then the Storage Connection String is UseDevelopmentStorage=true.
Please pay attention of it is a case sensitive.

After you finish your development and want to publish it on the cloud then you must register for Storage Account withing Azure portal and change your Storage Connection String properly in your code or configuration file.
Continue reading

ASP.Net Ajax Creating Multiple Calendar Extenders on TextBoxes Programmatically


A web app having multiple Textboxes and Date Pickers or Calendar Extenders are very common.
Usually a page for submitting more than one rows which include Date field.

If Textboxes with attached Calender depends on some logic then we need to create them programmatically.

I will show how to do it using Asp.Net Ajax Control Toolkit Calendar Extender as Date picker control. I also used the simple ‘Northwind’ sample Database for demo purpose.

This small application will show Employees Name, Title and Hire Date info. Hire Date can be choose using calendar extender & updated.

  1. Creating multiple TextBoxes and Calendar Extenders programmatically
    ...
    <form id="form1" runat="server">
        <div>
            <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
            </asp:ToolkitScriptManager>
            <asp:UpdatePanel ID="updpanel" runat="server">
            <ContentTemplate>
               
                <asp:Table ID="tblinput" runat="server" >
                    <asp:TableHeaderRow ID="TableHeaderRow1" runat="server" Font-Names="Calibri" Font-Size="10pt">
                        
                        <asp:TableHeaderCell>ID</asp:TableHeaderCell>
                        <asp:TableHeaderCell>Name</asp:TableHeaderCell>
                        <asp:TableHeaderCell>Title</asp:TableHeaderCell>
                        <asp:TableHeaderCell>Hire Date</asp:TableHeaderCell>
                    </asp:TableHeaderRow>
                    
                </asp:Table>
               
                <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                <asp:Button ID="btnSubmit" runat="server" Text="Submit" 
                    onclick="btnSubmit_Click" />  <asp:Label ID="lblmsg" runat="server"></asp:Label>
                
            </ContentTemplate>
            </asp:UpdatePanel>
        </div>
        </form>
    ...
    

    I have Table Control as container of Labels & TextBoxes. Also PlaceHolder control that will be contained by AjaxControlToolkit Calendar Extender.

    Labels, TextBoxes and Calendar Extender created programmatically inside Page_Load procedure.

  2. Continue reading

Scheduling Excel Report With SSRS 2008 R2 And ASP.Net

As default SQL Server Reporting Service 2008 R2 has Scheduled Report Generation named Subscription. You can choose what report and when to generate it also delivery method.

However this feature is quite standard. We must supply report’s Parameter manually to Subscription. So that in this blog I will show you how to make more flexible to this kind of schedule using Visual Basic Asp.Net

The generated report will be on Excel format.

Here are step by step:

  1. Prepare the report you want to sent and deploy Report Server
  2. Browse the report via http://Your_serverip/ReportServer and get its exact Url for example http://Your_serverip/ReportServer/Pages/ReportViewer.aspx?%2fYour_Report_Name&rs:Command=Render
  3. Continue reading

Creating Custom Asp.Net Web API using Handler .ASHX Also Example On Using It With JQuery And WebRequest

This blog post is about custom Asp.Net Web API and it is not like standard Web API using Web Api Controllers, Url routing etc.
I use general term or concept of Web API that is simply programming interface in a web. This can be done with many ways. Later on, the standard Microsoft Asp.Net Web API will be presented in this blog. API is just an additional layer in application usually to access data. Web API can be consumed by any device or method that support HTTP. With that concept, I use Handler .ASHX to make an Web API. This post shows custom Web API used by Client script with JQuery also by Asp.Net Server Control. I give those examples in below list. Steps for creating custom Web API using .ASHX:

  1. Create a Web Project
  2. Add new class as Model to represent data: (Persons.cs)
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    public class Persons
    {
        List&lt;Person&gt; list;
    	public Persons()
    	{
            list = new List&lt;Person&gt;()
            {
                new Person() { Id=1, FirstName="John", LastName="Doe", Department="A" },
                new Person() { Id=2, FirstName="Jane", LastName="Voltus", Department="A"},
                new Person() { Id=3, FirstName="Joseph", LastName="Chow", Department="B"}
            };
    
    	}
    
        public List&lt;Person&gt; getPersonList() {
            return list;
        }
    
        public void addPerson(Person p)
        {
            list.Add(p);
        }
    
        public void deletePerson(int Id)
        {
    		//code to delete
        }
        
    }
    
    public class Person
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string Department { get; set; }
    }
    

    Off course you can change to use database connection and so on.

Continue reading