Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Articles
Search: 

Bonnie Berent's .NET Tips
Bonnie DeWitt, September 1, 2005
Great tips for .NET developers
Summary
Great tips for .NET developers
Description

How To Isolate File Attributes
The key to isolating an attribute bit when using the System.IO.File.GetAttributes() method, is to bitwise-AND the value. For example, to determine if a file is ReadOnly, use IO.FileAttributes.ReadOnly (0x0001).
If (IO.File.GetAttributes(lcFile) And IO.FileAttributes.ReadOnly) = IO.FileAttributes.ReadOnly Then

from a solution provided by Keith Payne in Message #1035301

Maintaining Scroll Position in ASP.NET
You have a lengthy WebForm and the user has scrolled down a lot in the Page. How do you keep the Page from jumping back to the top when there is a postback? You could try using this code:
%@ Page SmartNavigation="true" %

But it only works for IE.

Here's an alternative that works for other browsers as well:
private void Page_Load(object sender, System.EventArgs e)
{
   if (!Page.IsPostBack)
   {
          // ...
   }
   RegisterHiddenField("__SCROLLLOC", "0");
   string saveScroll = 
      @"<script language='javascript'>
         function SaveScrollLocation () 
         {
            document.forms[0].__SCROLLLOC.value = document.body.scrollTop;
         }
         document.body.onscroll=SaveScrollLocation;
      </script>";

   if (!IsStartupScriptRegistered("saveScroll"))
   {
      RegisterStartupScript("saveScroll", saveScroll);
   }
   
   if (Page.IsPostBack)
   {
      string setScroll = 
         @"<script language='javascript'>
            function SetScrollLocation () 
            {
               document.body.scrollTop = " + Request["__SCROLLLOC"].ToString() + @";
            }
            document.body.onload=SetScrollLocation;
         </script>";
         
      if (!IsStartupScriptRegistered("setScroll"))
      {
         RegisterStartupScript("setScroll", setScroll);
      }
   }
}

from solutions provided by Viv Phillips and Çetin Basöz in Messages #1032096 and #1032145

Keeping DataGrids and TextBoxes in Sync
Why is it that sometimes your databound WinForm controls don't seem to want to stay in sync? Most likely you have a problem with the way you're databinding the controls.

There are two ways (two different syntaxes) to specify databinding for any control and this results in two distinct binding objects. The problem is that you can't mix and match ... you have to stay consistent throughout the form.

So, in other words, if you bound your DataGrid with:
this.oGrid.DataSource = MyDataSet;
this.oGrid.DataMember = "MyTable";

Then you have to use the following syntax with TextBoxes:
this.txtLastName.DataBindings.Add("Text", MyDataSet, "MyTable.LastName")

But if you bound your grid with:
this.oGrid.DataSource = MyDataSet.Tables["MyTable"];

Then you use this syntax for TextBoxes:
this.txtLastName.DataBindings.Add("Text", MyDataSet.Tables["MyTable"], "LastName")

from a solution provided by Bonnie Berent in Message #1036479

Displaying Images from a Database in ASP.NET
To serve up images from a database, first create a blank web form "ImageServ.aspx". In the page load, use Request.QueryString to get the PKID of the record containing the image and query the column into a byte array. Once you have the data, set the content-type of the response stream to the appropriate image type (jpeg, bmp, gif, or tiff) and send the byte array down the wire through the response stream.

Now in the web form that you want to display the image, put the URL of the ImageServ page with the PKID querystring in the ImageUrl property of an Image web control.

from a solution provided by Keith Payne in Message #1026676

Bonnie DeWitt, Geneva Systems Group
Bonnie is currently one of the principals of Geneva Systems Group. Call her the Senior Software Engineer, or even call her the VP of Engineering. She has no official title at the moment. Bonnie has been writing software in various languages for about 30 years. Bonnie's current focus on C# .NET applications began in early 2002. She has been a Microsoft C# MVP since Oct 2003 and an active member of the .NET online community.
More articles from this author
Bonnie DeWitt, October 1, 2005
Great tips for .NET developers
Bonnie DeWitt, November 1, 2005
Great tips for .NET developers
Bonnie DeWitt, December 1, 2005
Great tips for .NET developers
Bonnie DeWitt, April 1, 2009
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, February 1, 2006
Great tips for .NET developers
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers
Bonnie DeWitt, April 1, 2006
Great tips for .NET developers
Bonnie DeWitt, May 1, 2006
Great tips for .NET developers
Bonnie DeWitt, June 1, 2006
Great tips for .NET developers
Bonnie DeWitt, July 1, 2006
Great tips for .NET developers
Bonnie DeWitt, August 1, 2006
Great tips for .NET developers
Bonnie DeWitt, September 1, 2006
Great tips for .NET developers
Bonnie DeWitt, October 1, 2006
Great tips for .NET developers
Bonnie DeWitt, November 1, 2006
Great tips for .NET developers
Bonnie DeWitt, December 1, 2006
Great tips for .NET developers
Bonnie DeWitt, January 1, 2007
Great tips for .NET developers
Bonnie DeWitt, February 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2006
Great tips for .NET developers.
Bonnie DeWitt, April 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, March 1, 2007
Good tips for .NET developers.
Bonnie DeWitt, May 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, June 1, 2007
Great tips and tricks for .NET developers.
Bonnie DeWitt, July 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, August 1, 2007
Great tips for .NET developers
Bonnie DeWitt, September 1, 2007
Great tips for .NET developers.
Bonnie DeWitt, February 1, 2008
Great tips from the Universal Thread .NET community.
Bonnie DeWitt, March 1, 2008
Great tips for .NET developers selected from the community by Bonnie Berent.
Bonnie DeWitt, April 1, 2008
Great tips from the .NET developer community compiled by Bonnie Berent.
Bonnie DeWitt, January 1, 2006
Great tips for .NET developers