Monthly Archives: November 2014

Uploading the files – HTML5 and jQuery way!

Download the Sample from Dropbox

Most of the websites are using HTML5 and jQuery plugins, to upload the files without the user to have to send a POST request to the server, which is not a likely way of uploading the files.

Old way of uploading files

In old days, people likes to create a simple HTML form, and assign the encytype to it, that would let them select a file and then they will click on the Submit button which would then take them to a new page, where they will be shown the message, “Your photos have been uploaded” – or an error message telling them that there was an error. This is a bit irritating and awkward, because the user uploaded more like 5 photos among with one got an error, and the remaining 4 were also discarded and the user was told after 2 minutes to upload the 4 photos only and not that one particular image. Sometimes, connection is lost and other stuff!

New ways of uploading the files

The web is changing, and there are a lot of new ways in which the user can upload the image or his any file to the server, without having him to submit the form as he did back in 90s.

Using the iframes

Well before the HTML5, people used hidden iframes to target the form to be uploaded from, the iframe is just another HTML document embedded in your main HTML document, that if even navigated to any other web page doesn’t trigger any navigation event in the main page. Which means that if the form is submitted through an iframe the main page the user stands on it never submitted. But he can still view the results and other associated data, such as form elements and the result window.

HTML5 and JavaScript

But these are also old now, JavaScript is strong enough to upload your files, and using HTML5 you can easily work you way with the validations of Files too. You can manage which file to upload and which one to reject. This option also minimizes the chances of error for any file that were triggered in the old methods and the user was informed of those errors after he uploaded all of the HTTP request data.

In JavaScript, we can shorten down the code for creating an Ajax request – An Ajax request is an asynchronous request to the server to get some resources from the server and display it in the web page without needing to reload the web page. This technology (Ajax) enables us, to get any data to the web server without having to use the POST requests and reload the web page for the new content, and similarly it also enables us to send any data to the server – such as files, images and other data – to the web server. This makes the uploading of the content an easy method.

jQuery code

In this blog post, I will be using jQuery – why? because I love jQuery, it is shorter in syntax and looks cool, but remember it is slower than pure JavaScript because it is just a library that runs over JavaScript but the difference is barely noticable – to send the Ajax requests to the server, along with the file data that we want to be uploaded.

The first stage is to create the HTML form that will be capturing any of the file that the user wants to upload to the server. For example, the following code would be an example of the HTML form that will accept the files from the user and contains a simple button from which he will upload the files – I know, button is old method, but in this method this button won’t perform the built-in function, it will be captured by JavaScript and the page will stay where it is all using the JavaScript watch the jQuery code for more on this section.

<form method="post" id="form" enctype="multipart/form-data">
  <input type="file" name="file" />
  <input type="submit" value="Upload" />

Above is the example for the form. Now once we will look into the jQuery code, we will be able to omit the enctype=”multipart/form-data” part too. Until then, this form is – as it stands – will accept a (single; multiple files are not allowed yet) file and the Upload button will be used to trigger the main function.

The following is the JavaScript (jQuery) code that will capture the event and send a request alongwith the file.

$(document).ready(function () {
   // On the document ready
   $('input[type=submit]').click(function () {
     // Before the request starts, show the 'Loading message...'
     $('.result').text('File is being uploaded...');
     // On the click even,
     var formData = new FormData($('#form')[0]);
           type: 'POST',
           processData: false,
           contentType: false,
           data: formData,
           success: function (data) {
              // The file was uploaded successfully...
              $('.result').text('File was uploaded.');
           error: function (data) {
              // there was an error.
              $('.result').text('Whoops! There was an error in the request.');

.. in the above code, there is an element where the result is being rendered. That was like this,

<p class="result"></p>

.. in this element you will be showing the process that is currently going on.

  1. First of all – It will show a File is being uploaded… message in this paragraph.
  2. After the upload.
    If the file was uploaded, a success note will be shown otherwise an error message will be displayed to the user.

How will be button not submit the form by using a POST request? That is overridden by the code, in the second line inside the event handler. event.preventDefault(); in this code line, the default behaviour that will be triggered is overridden. Meaning that the page won’t be loaded again by a POST request, instead only that code will execute that we want – the Ajax code in the code block.

ASP.NET method to capture and make sure the request was having a File

You can use the following code of ASP.NET, that will make sure that the file is attached with the request, and then follow on to the Saving process and so on. For example this code,

files = Request.Files.Count;
if(files > 0) {
   // Files are sent!
   for (int i = 0; i < files; i++) {
      var file = Request.Files[i];
      // Got the image...
      string fileName = Path.GetFileName(file.FileName);
      // Save the file...
      file.SaveAs(Server.MapPath("~/" + fileName));

Above code will work, for any image or any file type. There is no validation until now, you can attach your own validations depending on the Mime type or the size of the file that was attached the request.

Omitting the enctype

Oh well, I said that after the jQuery code I will explain how can you omit the enctype attribute – or if you even miss writing the enctype the result will be valid to upload the file – is that when you’re using the FormData object, to send the data, it make the form to behave as if the enctype of the form was set to the multipart/form-data (which is required to encode the files and tranfer them on HTTP). ‘

That is why, even if you miss this part and are using the FormData you will see that the images are being uploaded to the server.

Points of Interest

HTML5 and jQuery are widely used frameworks to upload the files using Ajax request to the web servers making it easier to control the file types to be uploaded, validating the maximum file size to be uploaded and some other particular validation can be handled easily on the client-side making it easier for the user to perform uploading tasks fastly.

FormData is an object that once used makes it easy to encode the files and other data as if the form’s enctype was set to the multipart/form-data. This is used (and is required) to upload files on the server through HTTP requests.

You can prevent any default method to be executed upon any element or control, using the JavaScript’s preventDefault() method.

New developers and the Importance of C

Computer programming is a process in which programmer would create and develop softwares for the computers which would run a program, to solve a finite set of problems using a computer. Computer programming has been up since the beginning of computer system. In the first generation a vacuum tube was used, and after it since the transistors, binary language has been used to program the computers. Low-level programming has been introduced since Colossus; the first programmable computer.

Many changes have been made in this field and developers are stepping into this field to make computer systems even better than before. We are finding way better computers and their logic is even stronger than the previous era.

OS and the programming need

There was a need of an OS, since for each computer, the architecture was same and the programs that it would run were also same, but they had to write the same Operating System that would take control of the basic operations of the computer hardware for each of the computer seperately. So, many operating systems were introduced. Dennis Ritchie was the guy behind Linux OS and the C programming language. To teach those OSs, a language was required to tell the computer system what to do. Programming is a method of creating such applications, that would guide the computer’s system in executing the commands.

C is a low-level programming language, in which control over hardware is also provided. You can easily control the memory, processor and the registers using low-level language and you can manage the connected devices too. Assembly language is one of the first low-level language introduced after machine language (binary). But it was also less-understandable by humans as compared to C.

C programming language

C language is also known as the father of modern programming. Although there were other languages like BASIC and other some ones, but C was outstanding and outweighed in plus points as compared to them.

C language is a general-purpose programming language. There are no classes, no interfaces in C. But there are much more powerfull tools in it, pointers and much more. Which are used to manipulate the memory on the run time. C has been used as the building-block to many of the languages of the high-level programming, which include Java, D, Visual C#. C++ and Objective-c, when compiled, create a C language code and the C code is then compiled converting the code into native code enabling faster processing since the code is directly understandable by the computer once executed.

Why there are no more Good softwares anymore?

The new generation of the developers is really busy in their “get attention of public, specially girls” sort of thing and they lag the vital component of being a programmer. Which is, to help build a better digital world. I have been on to much forums, where new developers come and ask questions as vague as, why do I get Null error? I mean, really? This tells that the person, OP, doesnot have the very basic understanding of the concept “programming” and he just heard that Bill Gates is the richest person alive, he build a computer software known as MS-DOS and hey man, I can do the same here. All I have to do is to create a software and yeah, I will be a billionaire. This mentallity of the new developers doesn’t let them win the race.

Why learn C

C programming is vital, and must be taught instead of C++. Although C++ covers the concepts of Object-oriented programming but C is the main language that almost 90% of the programmers must know. 10% can rely on the C++ or any other high-level language. On my journey, I have leart Visual C#, Java, Visual C++, Visual Basic, ASP.NET and many more languages and I have always found people complaining about the speed of the language and the answer was always to learn C language or to use C++, since they compile down to the native code making it faster for the applicaiton to run.

Problems at College level

The college I study at teaches us; or should I say only taught us, C++ for 2 months and it was all craming; murder of the programming concept is to teach programming on paper. Although it is because the lack of resources here, but still new programmers must be taught the programming skills. I remember my days  of HTML learning, although it was never a tough language but for me, without any knowledge and understand the ASP.NET code was like a petition against me.

Side-effects of not learning low-lever programming language

Most of the embedded devices require low-level programming, most of the microcontrollers require the developer to have enough understanding of the low-level programming, and the concepts involved in low-level programming. Such as memory management, pointers and other concepts that are required in programming for microcontrollers, or other microchips and embedded devices. For a modern developer (a developer who can only write applications on .NET framework, or Android OS) would never be able to program for such devices. There is another concept called Internet of Things, that can be however programmed using the .NET but devices connceted to it must be programmed using a low-level language for a better output.

No general support of these languages

There is no support for C and other programming language, such as Assembly, and the best IDE (at least in my opinion) Visual Studio doesn’t support the Assemly projects, but still MASM is included. That is why, the major colleges and institutions teaching software engineering and computer programming do not teach Assembly, C, or any other programming language that explains the computer programming concept in real. This removes any traces and interest of a programming student to better understand the computer architect and then product the softwares for it. But instead the programmers are more-likely to be developing the applications for themself, and not for the public use.

Do or die; C or blind

Students must be taught the difference between a low-level programming and the high-level programming and their minds must be set to always prefer low-level programming instead of high-level programming. You can think of it as the programmer must always go to the harder but efficient way and must always ignore the easy but vague way of doing programming. A framework that he built the application might at any time get deprecated and so on. But an application developed using the low-level programming language would never fall short any time. This ensures not only the efficiency, but the quality of the application. Low-level programming is also not bad for the person, it makes his mind able to solve basic riddles that he might face each day.

Online resource for learning C

I have been searching for a C compiler and a resource library to look deep into the C language, and I found the resource library at The C Library Reference Guide. Online compiler can be easily accessed at, Compile and Execute C Online.

Programming is the best hobby for mind, if done in a low-level language.

SEO items

Tips for better SEO and better ranking

Now adays people are running into SEO troubles and are trying to use fake softwares and methods to get their website on the top list or the top rank in some particular keyword. Many people try to hire a programmer to program such a software that would run entire night and will keep giving their website clicks and will go back all of a sudden. Well that doesn’t work here.

In this post, I will try to explain the basic concepts; not the core concepts, of how to get your website in a better ranking stage. Being the first isn’t the bid, if you can be the first it’s a great thing for you and your business but don’t fight for the rank, fight for the better audience that you’re going to encounter. Make sure they’re relavant to your website. For example, if you’re having a website where you sell handicrafts, where as your website is having multiple keywords like, good handicrafts, handicrafts, handmade crafts and many more of this type. Then users that might search for Images of Handicrafts would also redirect to your website and would never purchase. This type of the user is not good for your business since you’re there to sell stuff not to just show it to the public.

SEO items

SEO – categories

What is SEO

SEO stands for Search Engine Optimization, it enables you to easily configure your website to perform better so that the search engine might understand your website, its theme and purpose and will categorize it in the correct category. There are many methods that you can use to control the SEO ranking, you can always make your web content better to allow the Search Engine understand your purpose and your audience.

This helps the Search Engine to show your website to the correct audience without any trouble. It also helps your company to grow in business and to get more users and clients.

Every company needs to have an SEO team for their company in today’s world to compete with their internet rivals. Google, Bing, Yahoo and many other Internet Search Engines are running day and night providing results to the searches of the clients. If there is a client for you, you won’t want him to go away just because your ranking was low on the Search Engine’s search results page.

What can I do?

Well, there are many options for you, you can either hire an SEO, or a team of SEO professionals to work for you. Or you can at the same time, learn the SEO tips on your own and optimize your website on your own. This will help you better understand the Search Engine and letting it understand your requirements of the audience.

Good SEO can be seen as a collection of following concepts in your website,

SEO requirements.

For a better result of SEO, ensuring good quality of these items is obligatory.

Good URLs

Search engines are smart enough to understand the links, whether the link (URL) is a dynamic (e.g., static and all that other type of page related stuff.

You need to be ensuring a good quality of URLs, make sure they’re all Query String free. In ASP.NET you can use the UrlData to ensure the QueryString is appended to the URL in the form a sub page or a sub folder and so on. Also, if must be noted that the URL and the Title must match. If I am having a Title for my website as “Afzaal Ahmad Zeeshan, Student, Learner” and the URL is as, “;, it won’t be a good URL, and would result in bad impressions.

Meta tags are still alive

Well most of the time the discussion is that we should not focus on the meta tags. But remember, they are still alive and are a part of HTML. We should use them where required and we should always try to make them user and search engine friendly. This would help us to get a better result on the Search Engine ranking system.

Adding good description for your web page might contain,

  1. Good description for the web content.
  2. Unique and short, but must comply with the above.

Good UI

Although Search Engines don’t worry about the CSS of your website. But still, you need to use a semantic web design to ensure that the Search Engine don’t feel anything bad coming at it. Usage of heading or paragraph element, adding button class and then using them as a list item is not a good UI. As per HTML5, the web has been semantic and there is an element for each and every purpose. You don’t need to be using the very old technique for using a div element and then styling it as it to look like a control from some other GUI.

Right now, HTML5 contains elements for almost all of your stuff, unused and not required elements have been removed from the API forever and HTML5 now has a great set of elements for you. You can use them. This doesn’t only make the developmental process easy but also explains the Search Engine that the UI is correct for the purpose it is meant for.

Linking to your website

Since a web crawler crawls each and every link that comes to its range. It is also good to add links to your own pages in the web page.

Adding these links would make sure that your pages are indexed in the web search, and that the crawler has crawled through your page.

Sharing is Caring

Yes, this motto is true and sharing is really caring. Caring for others? Well I am talking about your business here not others. When you add a social plugin where people can share your content, they’re actually playing your role, and sharing the content on the Internet. Through Google, Bing you will get more clients, same thing can be done using the Social Plugins. These plugins mostly have a built-in stats calculator that most of the companies use to determine the quality of the website to view it to more public if people love it.

Google+, Facebook, Twitter and many more companies have joined hands to collect stats from their social plugins and then show the content of a website to the targetted audience only.

You can use the Social plugins to perform the following actions,

  1. Allow people to share your content,
  2. Allow then to comment.
    While they comment, it adds a set of detail to your website and the product. Which is added by the audience, now you. It helps!
  3. Make sure there is no spam content there, add a moderation to your website. Search Enginers don’t like spam content.
Social buttons.

Social Buttons on your website. Designing these buttons is a really very good method for introducing the client with this feature. You can allow them to share the content.

No Spam please

No spamming tolerated on Internet.

No spamming tolerated on Internet.

We all want a free internet, for that most of the people spam their content, either by posting it on someone else’s page. By hiding the actual content behind a beautiful deal. Search Engines don’t like stuff like this. If the stuff on the page isn’t matching to the stuff in the meta tag, or the title of the page. There is something fishy going on and Search Engine will take its right and will move ahead from that page.

Using online Tools

Search Engine giants provide you with a interface that lets you work with their SEOs back end code. For example, Google provides Web Master, Analytics etc to let you see what is going on with your website and the SEO. Bing and Yahoo also enable you to do this.

Using these tools you can,

  1. View the reports for your website.
  2. Manage the reports and ranking of your website.
  3. Check which keywords and locations are liking your website and where you need to work more.
  4. They sometimes even help you out to make your website rank better.

Search engines are very intelligent, they’re hardly tricked. You can use the Search Engine to rank better, or you can try tricking it forever and failing forever. If you stay close to the objectives and the methodology provided by the SEO companies and use them to build your website, you will definitely get a good result. There is no strictness here, it is just to stay focused on your main idea and purpose of web page. If you stick to the main purpose, your website is gonna get a good ranking among the targetted audience.