Popular Posts

Thursday, January 26, 2012

Download file inASP.Net



 public static void downloadFile(System.Web.UI.Page pg, string filepath)
    {
        pg.Response.AppendHeader("content-disposition", "attachment; filename=" + new FileInfo(filepath).Name);
        pg.Response.ContentType = getContentType(new FileInfo(filepath).Extension);
        pg.Response.WriteFile(filepath);
        pg.Response.End();
    }

Content type:
 public static string getContentType(string Fileext)
    {

        string contenttype = "";
        switch (Fileext)
        {
            case ".xls":
                contenttype = "application/vnd.ms-excel";
                break;
            case ".doc":
                contenttype = "application/msword";
                break;
            case ".ppt":
                contenttype = "application/vnd.ms-powerpoint";
                break;
            case ".pdf":
                contenttype = "application/pdf";
                break;
            case ".jpg":
            case ".jpeg":
                contenttype = "image/jpeg";
                break;
            case ".gif":
                contenttype = "image/gif";
                break;
            case ".ico":
                contenttype = "image/vnd.microsoft.icon";
                break;
            case ".zip":
                contenttype = "application/zip";
                break;
            default: contenttype = "";
                break;
        }
        return contenttype;
    }



calling:

        downloadFile(this.Page, Server.MapPath("~/images/image1.jpg"));

Resizing the Silverlight contents according to screen resolution



private Tuple<int, int> GetScreenResolution()
{
var contents = Application.Current.Host.Content;
bool wasFullScreen = contents.IsFullScreen;

try
{

if (!wasFullScreen)
{
contents.IsFullScreen = true;
}

if (!contents.IsFullScreen)
{
return new Tuple<int, int>(0, 0);
}

int width = (int)Math.Round(contents.ActualWidth);
int height = (int)Math.Round(contents.ActualHeight);

return new Tuple<int, int>(width, height);
}
finally
{
if (contents.IsFullScreen != wasFullScreen)
{
contents.IsFullScreen = wasFullScreen;
}
}


Content position according to your Screen in silverlight


private Tuple<int, int> GetScreenResolution()
{
var contents = Application.Current.Host.Content;
bool wasFullScreen = contents.IsFullScreen;

try
{

if (!wasFullScreen)
{
contents.IsFullScreen = true;
}

if (!contents.IsFullScreen)
{
return new Tuple<int, int>(0, 0);
}

int width = (int)Math.Round(contents.ActualWidth);
int height = (int)Math.Round(contents.ActualHeight);

return new Tuple<int, int>(width, height);
}
finally
{
if (contents.IsFullScreen != wasFullScreen)
{
contents.IsFullScreen = wasFullScreen;
}
}
}

Current Time

<iframe src="http://free.timeanddate.com/clock/i2yc1jom/n176/tlin/fs15/fcf00/ftbu/tt0/tw1" frameborder="0" width="239" height="20"></iframe>

Saturday, January 21, 2012

Load file in the Div

below code is for load file in a Div.

WebClient MyWebClient = new WebClient();

Byte[] PageHTMLBytes;

PageHTMLBytes = MyWebClient.DownloadData("http://abc.html");

UTF8Encoding oUTF8 = new UTF8Encoding();

divName.InnerHtml = oUTF8.GetString(PageHTMLBytes);

Auto scroll the page


string script = "window.scrollTo(0,950);";

ClientScript.RegisterStartupScript(this.GetType(), "scroll", script, true);