Tutorials

How to force download a file using ASP.NET

There are many cases where we need to let file downloads being processed by an aspx file. Here in this code this code will force a file to be downloaded through an aspx file. let assume your file path  is in “string path” variable. Add this code in your aspx file cs file.

 


string path = "the path to your file";
string fileName = "Add your file name";
string contentType= "Add your file content type. ex: for text file it is 'text/plain'";
string contentLength = "add string presentation of your file size in bytes";

response.Clear();
response.ClearHeaders();
response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
response.AddHeader("Content-Length", contentLength);
response.ContentType = contentType;
FileStream f = new FileStream(path, FileMode.Open);
byte[] buffer = new byte[8 * 1024];
int len;
while ((len = f.Read(buffer, 0, buffer.Length)) > 0)
{
    response.OutputStream.Write(buffer, 0, len);
}
response.OutputStream.Flush();
response.OutputStream.Close();
response.Flush();
response.Close();
response.End();
No Comments

Group by date from a datetime or timestamp field in Mysql

This is a simple but greatly useful mysql query. You can use it to find all the dates even with time included in datetime or timestamp field.

No Comments

Read more

Create custom notification on your Ubuntu desktop using python

You can easily create custom notifications for your applications on ubuntu. Ubuntu’s current notification system is called NotifyOSD. It provides api for several languages. Using python-notify library it is really so easy than in any other.

Ubuntu by default have the python-notify installed. If don’t install it using

sudo apt-get install python-notify
No Comments

Read more

Convert unicode codepoints to unicode hex values in java

In a part of our crawler development, we encountered a Bangla news site (http://www.kalerkantho.com/) which uses code points instead of unicode hex valus in their website. Although it renders banla fonts in browser, but when viewings source it only shows code points, so when downloaded by crawler we only got কકى similar.  For the indexing purpose we needed to convert them to hex values so that it renders bangla font anywhere. The process of converting is really so simple.

1 Comment

Read more

Extract hyperlinks from html using regular expression in java

2 years ago, I worked with an crawler which can fetch webpages from internet, then parse the links from the page and then visit all the pages linked to the page. At that time I didn't have any idea about regular expressions. So I had to write around a 500 hundred line code to parse links and meta tags from html.

Yesterday, I had to do the same job again. This time I took up regular expression to parse the html <a tags followed by href attribute to extract the links.

Regular expressions can be difficult to understand if written at once, so I am going to write it in easy way first, then i ll make it complex to support variations in page links.

No Comments

Read more

How to allow users to execute sudo command in ubuntu

If you have a user account that cannot make sudo command then it because it is not in sudoers list. You must add the user to sudoers list to allow sudo command. Sudoers list is located in /etc/sudoers

 

So open up the file with visudo command. You must use this command to edit this

No Comments

Read more

How to add users and usergroup in ubuntu using terminal

It is very easy to create new user account in ubuntu using terminal. Just follow adduser and addgroup command.

Here is an example

I want to create a user named "nutch" with a new "nutch" user group. Here is how I did it.

No Comments

Read more

Change root user password in ubuntu using terminal (The short way)

If you forget the root user password you can change with a simple tricky command in ubuntu. Login to your regular account. You should have the sudo comman available for your user account.

Now open the terminal and enter the command

sudo passwd

This will let you to change root account password as you used sudo! Now enter the new password and confirm. Yes! You are done :)

No Comments

Turn of php register_globals locally

PHP global variables are used to set set variables globally. This feature were used vastly in past. But with time it has been proved as a sercurity threat for websites and server. So now a days most of the good php applications dont use this feature. PHP also highly discourages using this feature. Most of the new applications and good cms like drupal, wordpress, joomla requires this to be turned off.

No Comments

Read more

Learn meaning of http response codes

What is http response code?

http response codes are some numbers sent to browser from server each a http request is made. Each of them has different meanings. They tells you how server response to the request url. Here is a details of all the available http codes.

1 Comment

Read more

Page 1 of 712345NextLast »