Web Development

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

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

Compress css files using php

Have you ever noticed the css files from giants like google, yahoo or facebook. If you look at them you will see they are very tightly coded no space, tabs or line breaks yet a very large css file. How they manage it to debug when it is not human friendly to view the code.

5 Comments

Read more

Clean URLs by removing /index.php/ from urls in codeigniter

In codeigniter you can easily use very search engine friendly urls.

By default it is shown as

http://www.yoursite.com/index.php/controller_name/function/id

You can easily remove this disgusting index.php from your urls.

3 Comments

Read more

Execute shell command on server using php

Accessing shell command in server may not be available for you at all due to security reasons. But still you can access it using php since this will give you some extra features and time saving efforts. One of the example is to creating backup of your files. You might want to create backup of your files in gz format. But you may not have this feature in your cpanel or being banned by your hosting company. If you can make access to the shell of your server and execute tar command who can stop you from??!!

No Comments

Read more

3 important settings to make with custom php.ini

PHP.INI is the php configuration file that server uses. It makes lots of settings in an web server. It may include your site base directory, include path, temporary directory, timezone and lots of different php varaibles. Most of them are set by web hosts and you cannot make any change of them unless your are the host owner. But some setting you must make to let your site run smoothly and securely. So we must override some settings by putting an php.ini file. This will allow you to override some configurations of your host.

No Comments

Read more

Create tree view in webpages using Google Visulaization Api

Today I am going to tell you about how to create a tree view or binary tree view in webpage using some apis like Google Ajax Api (Visualization Api)

Few days ago I was working with a multi level marketting (MLM) management  software where users are being registered under another refereing user. Thus forming a binary tree. I badly needed to create a tree view in web page. I searched the net for a easy solution. But the searched results were getting meshed up with result like creating folder trees. I didnt too much resources on net about it. Finally I found that its Google providing an ajax api called Google Visualization API that are providing some good tools for visualizing an charts. One of them is organizational chart found in Google Visualization API Gallery.

No Comments

Read more

Fix 500 internal error after uploading drupal site to host

After uploading dscripts.net new site to host it was reallty getting so much boring with 500 internal errors. I developed this site in localhost for last two weeks and when I upload it to my host (http://www.hostgator.com) things started going wrong.

It was arround two nights hard work before I could fix it. I googled and found that having 500 internal error after uploading a drupal site is quite common. It may have lots of reasons.

No Comments

Read more

Configure CKEditor with syntax highlighter in drupal

I ran an website with programming tutorials and related resources with drupal. I need to add lots of reference codes in my posts. So I use javascript SyntaxHighlighter library from http://alexgorbatchev.com/wiki/SyntaxHighlighter.

In my drupal website I have fantastic wysiwyg editor module called ckeditor with lots of reach features. But when I need to add any code in my post. I manually need to switch to source mood and then edit the html to enter the syntaxHighlighter syntax.

1 Comment

Read more

Page 1 of 3123