Showing posts with label Browser. Show all posts
Showing posts with label Browser. Show all posts

Thursday, May 3, 2012

Open MS Word document in web browser

 

This is one of the common request you will get when you do any file operation in your project. This code can be used to open EXCEL, Power Point, PDF etc.

protected void btnWord_Click(object sender, EventArgs e)
{
    string strWordFile = @"c:/Test.docx";
    FileInfo objDoc = new FileInfo(strWordFile);
    Response.Clear();
    Response.ContentType = "Application/msword";
    Response.AddHeader("content-disposition", "attachment;filename=" + objDoc.Name);
    Response.AddHeader("Content-Length", objDoc.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.TransmitFile(objDoc.FullName); 
    Response.End(); 
}

Sunday, February 26, 2012

How to add URL in favourites using ASP.NET and JavaScript

One another regular question in forum. This is a simple code which helps you to add URL in favourites. Here I have used both JavaScript and ASP.NET code.

I am giving two sample code here.

Method 1:

First we will add the current URL by opening Add URL pop up and allow the user to enter the favourites URL title.

//btnAddFavourites is the button name 
btnAddFavourites.Attributes.Add("OnClick", "window.external.AddFavorite(location.href, document.title); return true;");

Below is the pop up window sample,

image

Method 2:

In this method we will not take any input from user. We will add a simple JavaScript function and hard code both the URL and Title.

Add below JavaScrit just below your <head> opening tag,

<script language="javascript">
        function AddToFav()
        {
        bookmarkurl= "http://asheej.blogspot.com/";
        bookmarktitle="Good .NET Articles"
        if (document.all)
        window.external.AddFavorite(bookmarkurl,bookmarktitle)
        else if (window.sidebar) // firefox
        window.sidebar.addPanel(bookmarktitle, bookmarkurl, "");
        }
    </script>

Now we will call this function on button click,

//btnAddFavourites is the button name
btnAddFavourites.Attributes.Add("OnClick", "AddToFav(); return true;");

Just try this in your website.

Cheers Asheej!

Wednesday, July 7, 2010

How to find Browser type and version from code behind?

Copy paste below code in your code behind and see the out put!!!!!

string strBrowser= Request.Browser.Browser;//Display the browser type like IE, Mozilla etc.

string strBrowserVersion= Request.Browser.Version;//Display the browser version like IE 8.0,8.2 based on the release.

int intBrowserMajorVersion= Request.Browser.MajorVersion;//Display Browser major version like in IE 6,7,8

double dblBrowserMinorVersion= Request.Browser.MinorVersion;//Display Brwser Minor version like IE 1,2,3 based on the release.