Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Monday, May 17, 2010

How to minimize window from closing C# windows application

To minimize the window when user closes the form, use the code below.

 private void Alerts_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {               
                e.Cancel = true;
        this.WindowState = FormWindowState.Minimized;

            }           
        }

Add To Google BookmarksStumble ThisFav This With TechnoratiAdd To Del.icio.usDigg ThisAdd To RedditTwit ThisAdd To FacebookAdd To Yahoo

Thursday, May 13, 2010

How to prevent form closing in C# windows application

In some cases you need to prevent closing the application/form when user clicks windows close button.

Use the following code snippet to do so

 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
            }
        }

Add To Google BookmarksStumble ThisFav This With TechnoratiAdd To Del.icio.usDigg ThisAdd To RedditTwit ThisAdd To FacebookAdd To Yahoo

Thursday, November 20, 2008

How to make Visual Studio 2005 build process faster

To make build process in visual studio 2005 faster, change Start Action in property page.



Right click on the solution and click on properties. Change Start action into 'Build Page' instead of 'Build Website'

Add To Google BookmarksStumble ThisFav This With TechnoratiAdd To Del.icio.usDigg ThisAdd To RedditTwit ThisAdd To FacebookAdd To Yahoo

Monday, September 8, 2008

How to prompt for Download for a known MIME type

Sometimes you may require a link to download some files like jpg, gif, html etc. But these are known mime types and if you just give a 'href' link it opens in the browser itself. To prompt the user for 'Save as' you need to use the following steps,

Response.ContentType = "application/x-unknown";
string fileName = "file.jpg";
string filePath = "d:\\" + fileName;
Response.AddHeader("Content-Disposition","attachment; filename=" + fileName );
FileStream fs = File.OpenRead(filePath);
BinaryReader br = new BinaryReader(fs);
Response.BinaryWrite(br.ReadBytes(Convert.ToInt32(fs.Length)));
Response.End();

This is code in c#. Similar way you can use this in any other scripting language.

Tags: Response.ContentType, Content-Disposition, ASP.NET, C#, Download a file using c# and ASP.NET

Add To Google BookmarksStumble ThisFav This With TechnoratiAdd To Del.icio.usDigg ThisAdd To RedditTwit ThisAdd To FacebookAdd To Yahoo