CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Mark DiGiovanni

Software Development and Supporting Technologies
  • Richmond Code Camp 3 Presentations

    Richmond Code Camp 3 was a huge success. There were some really great topics presented and prizes given away.

    I presented two sessions on WPF. The first on XAML and the second on Code; both sessions were based on the most excellent book by Charles Petzold called Applications = Code + Markup, A Guide to the Microsoft Windows Presentation Foundation. If you are new to WPF and have .NET development experience with C#, then this book is for you.

    The slide decks will be published shortly. You will be able to download them here:

    --Mark

    Posted May 01 2007, 08:56 AM by mdigiovanni with no comments
    Filed under:
  • Retrieve the Current User & Set the Combo Box: Access 2003

    It’s been six years since I did any real Microsoft Access development.  I am currently on a short engagement to enhance an Access database for a “Major Nationwide Electronics and Stuff Retailer.”  In reality, I’m building them a completely new database.   I am hoping that this will lead to an overhaul of their department operations, which I hope will lead to a lengthy .NET conversion project.  A lot of applications actually start out this way.  I’ve worked on several Microsoft Office application to .NET conversions.   Access programming may not be as glamorous as say building .NET driven robots, but it is still pretty fun.


    Retrieve the UserName

    To retrieve the currently logged in user, created a helper class, and place the following method in it:

    Public Function GetCurrentUserName() As String

    GetCurrentUserName = Environ("USERNAME")

    End Function

    In the old days of Access programming, a complicated API call had to be made to achieve the above.   The example will also work in other Office applications.


    Retrieve the UserID from the Users Table



    Create a table of Users that contains the UserID, UserName, FirstName, LastName, and so on.   Then match the value returned from GetCurrentUserName() with the value that is in the UserName field of the table.  Use the following method to retrieve any given value from the Users table based upon the UserName:

    Public Function GetUserNamePart(returnPart As String) As String

    Dim user As String
    user = GetCurrentUserName

    Dim cmdText As String
    cmdText = "SELECT " & returnPart & " FROM Users WHERE UserName = '" & user & "'"

    Dim cmd As New ADODB.Command
    cmd.ActiveConnection = CurrentProject.Connection
    cmd.CommandText = cmdText

    Dim rst As New ADODB.recordset
    Set rst = cmd.Execute

    Dim namePartValue As String

    If Not rst.BOF And Not rst.EOF Then

        namePartValue = rst(0).value

    Else

        namePartValue = user
       
    End If

    rst.Close
    Set rst = Nothing
    Set cmd = Nothing

    GetUserNamePart = namePartValue

    End Function


    For example, if the UserID is need, make the following call to the above method:

    Public Function GetUserID() As Long

    GetUserID= GetUserNamePart("UserID")

    End Function


    Set the Default Value of the Combo Box


    I have forms that track various bits of data that can be associated with a person other than the current user.  I created a Combo Box that is bound to the UserID of the table that is bound to the form, while the Combo Box gets its display data from the Users table.  When the value of the Combo Box changes, it will be stored in the table that is bound to the form.  Without making any changes, the Combo Box will default to the first row that is retrieved.  This can become painful if the user has a last name that starts with “S” or a latter letter in the alphabet and has to key in 100+ items.

    On the Form_Load() event of the form, add the following code:

    UserList.DefaultValue = HelperFunctions.GetUserID

    This will tell the Combo Box to default to the currently logged in user, and will also give the user the ability to change the value.


    Additional Resources:
    http://blogs.officezealot.com/charles/archive/2004/12/10/3574.aspx
    http://www.vba-programmer.com/

    --Mark
     


  • Windows CE Emulator Error Message

    I finally got my Virtual PC development environment configured so I can develop a Windows CE application in Visual Studio.NET 2003.  I created a new project (Smart Device Application), then pressed F5 to see what would happen.  Here is the error message I received.


    --Mark

  • Publishing Office Documents as HTML to SharePoint

    My boss came to me today with the need to have a list he is maintaining published to a SharePoint site.  This list needed to be viewed only by a select group of people.  This list was rather dynamic, and columns could be added or removed as needed.  He needed this published by COB today.  He also requires the ability to publish this list whenever the need arises.

    The solution I implemented only took about five minutes of my time.  Here is what I did:

    SharePoint Configuration:
    • Created a site and added my boss as an administrator. (He can add people as he see fit).
    • Modified the homepage.  I removed all the default web parts except events.
    • Added a Page Viewer Web Part and the widths were set to 900 by 900 pixels and set the Frame Style to none.
    • Added a default webpage called pageview.htm (you can name this whatever you like) to the Shared Documents document library.
    • Pointed the Page Viewer Web Part to pageview.htm.
    Office Application Configuration:
    • Saved Excel file as a webpage and name it pageview.htm --works with Word too :).
    • Uploaded this document to the Shared Documents document library of the new site.
    • Alternatively, you can tell the office application to publish to the document library (on Save As).
    I accomplished all of this in under five minutes.  Now my boss can make changes to his document, and share it as a webpage whenever he likes.  The best part is that he can do this himself.  He doesn't need an "IT" person to push a webpage to the portal site.

    --Mark
  • Problems with Rhapsody to Go

    Surprisingly, this is actually my first "rant" of 2005.  I am completely frustrated with Real Networks new Rhapsody subscription, "Rhapsody to Go."

    On April 26th, Real Networks announced Rhapsody 3.0 and a new subscription tiers.  So I upgraded to Rhapsody to Go.  This subscription is $14.99 per month, and is supposed to allow you to download all the music you want to your portable device.  Take a look at their help documentation here.

    The device I am transferring to is my IPod Shuffle which is supported (http://music.guide.real.com/rhapsodydevices).  Here is my problem: every time I try to transfer music to my portable device, I get prompted to pay 89 cents for each song that I want to transfer.

    So I emailed customer support twice, then finally called (to get a phone number, you have to try to cancel your subscription from within Rhapsody).  They told me that anytime I want to transfer music I have to pay 89 cents regardless of the "To Go" subscription that I have.  This in complete contradiction to what they are advertising with their subscription serviceQuite frankly, I am in disbelief.  This seems to me like false advertising, pure and simple.

    [Update (thanks to Brandon Paddock) :  It seems that I, along with the Rhapsody customer service reps missed the little bit of info :

    Basic: Plays simple MP3, WMA, AAC etc.
    Download: Plays all of the above, PLUS secure music purchased from Rhapsody
    Subscription: Plays all of the above, PLUS subscription downloads from Rhapsody To Go

    I wish this was posted in a more conspicuous place]

    This is the first paragraph from this help file:

    "A portable player or device allows you to take your local music with you wherever you go. But with a the appropriate Rhapsody subscription, you can download and transfer thousands of Rhapsody subscription tracks, at no additional cost beyond your subscription rates. Much of the vast Rhapsody Music Guide library is yours to put in your pocket and take with you anywhere."

    This is from their advertisement from their site:

    • Unlimited access to over 1 million songs
    • Unlimited transfers to your portable devices
    • Unlimited pre-programmed and custom radio
    • Effortless music playback and discovery
    • Personalized music recommendations

    These statements clearly state that I do not have to pay for each song.  What part of "no additional cost" includes 89 cents per track?  What part of "Unlimited transfers to your portable devices" includes 89 cents per track?

    I have since cancelled my Rhapsody subscription, and I will purchase one or two albums from ITunes a month from now on.

    --Mark

  • Command-Line switches (parameters) for Virtual PC 2004

    Here is a few switches (parameters) that you can use to start Virtual PC 2004:

    •  -singlepc
      The -singlepc parameter starts the specified virtual machine without starting Virtual PC Console. This parameter can simplify the Virtual PC interface in a corporate or lab environment where users only want to access a virtual machine and do not have to use Virtual PC Console. You can use this parameter only during Virtual PC startup.
    • -quiet
      The -quiet parameter prevents the starting of any virtual machines that are configured to start automatically. You can use this parameter only during Virtual PC startup.
    • -usehostdiskcache
      The -usehostdiskcache parameter turns on host-side disk caching. Host-side disk caching can improve the performance of virtual machines that run operating systems other than Windows. This parameter can help to resolve poor performance problems with disk-intensive tasks. You can use this parameter only during Virtual PC startup.-pc virtual_machine_name
      The -pc virtual_machine_name parameter specifies to perform operations on a specific virtual machine. The virtual_machine_name is the name that appears in Virtual PC Console and the virtual machine window for the virtual machine.

      Note: virtual_machine_name  is case sensitive.

    You can use these either from the command-line or by creating a shortcut with the target set like this:

    "C:\Program Files\Microsoft Virtual PC\Virtual PC.exe" -usehostdiskcache

    You can find more switches here.

    --Mark

  • Optimizing Development with Microsoft Virtual PC 2004

    I've written an article about Optimizing Development with Microsoft Virtual PC 2004.  This product caused me to rethink the way I configure my laptop for enterprise development.


    Read on here.

    --Mark
  • WeProgram.Net site

    Our new site is up.  Many thanks to Greg Postlewait for all his hard work.  My presentation materials from our last meeting on March 8th, "One Part Enterprise Library, One Part VistaDB, and A Dash of Resharper" are online and located here.  If you are new to the Enterprise Library, make sure to look at these walkthroughs; they are really good.

    Previous post on this topic.

    --Mark

  • User Agent Switcher plug-in for Firefox

    Here is a plugin that I came across today.  It switches the user agent in Firefox to fool the website into thinking it's IE, Opera, etc.

    --Mark

  • Presenting at WeProgram.Net

    Tomorrow I will be presenting the following topic:

    "One Part Enterprise Library, One Part VistaDB, and A Dash of Resharper"

    This has been a fun topic to put together.  Basically, I will be confining my talk to the Data Access Application Block, how to write a custom data provider to interface with VistaDB via this application block, and how Resharper can help the developer be more productive.

    I plan on recording this presentation with Windows Media Encoder, and making it available for on-line viewing.  We'll see how it goes.  I definitely will make the slide deck and the code examples available.

    We will be giving a $900 pass to Devscovery, at least 2 licenses for VistaDB, two licenses for Resharper, and everyone who attends will receive a 20% discount on their purchase of Resharper.

    for more info, visit the following:

    WeProgram.Net
    Microsoft Patterns and Practices, Enterprise Library
    VistaDB
    Resharper

    Update:  Materials are now available here.

    Mark

  • How to change portal navigation in SharePoint 2003

    These are two great articles.

    In researching how to modify the default navigation in SharePoint Portal Server 2003, I came across these articles:

    Branding a SharePoint Portal Server 2003 Site: Part 1, Understanding the Use of a Corporate Brand.

    The second article discusses modifying the left area navigation and creating a breadcrumb.

    Branding a SharePoint Portal Server 2003 Site: Part 2, How to Apply Your Own Corporate Brand.

    --Mark

  • Shorter hours in software

    It seems that shorter work days are the new trend in the software industry.  I think EA helped bring this to the forefront, but companies may not be all to blame.

    A tough-guy culture among coders also seems to have been a factor. Last year, the International Game Developers Association cited this as a reason for horrible working conditions in the computer game world.

    "Developers are sometimes just as much to blame for submitting themselves to extreme working conditions, adopting a macho bravado in hopes of 'proving' themselves worthy for the industry," the professional group's board said in a statement.

    Does working overtime produce more work?

    Research indicates that long hours don't translate into heaps of extra work. Consultant DeMarco has studied productivity data and concluded that workers putting in 44 hours per week generate the same amount of work as those who put in 36 or 37 hours.

    "There's nothing to be gained from the extra hours," he said. DeMarco argues that there are limits to how much people can churn out without adequate breaks, and companies with cultures of long days tend not to run meetings in a disciplined fashion.

    Read on here.

    —Mark

  • Determine User Site Group (Role) Membership in SharePoint 2003

    Since there is no method to test whether a user is a member of a specific SharePoint Site Group such as Reader, Member, etc., use the following method:

            private bool IsCurrentUserInRole(string role)
            {
                bool inRole= false;

                SPWeb rootWeb = SPControl.GetContextSite(Context).RootWeb;
                SPRole  spRole = rootWeb.Roles[role];
                SPUser currentUser = rootWeb.CurrentUser;
       
                foreach(SPUser roleUser in spRole.Users)
                {
                    if(roleUser.ID.Equals(currentUser.ID))
                    {
                        inRole= true;
                        break;
                    }
                }

                return inRole;
            }

    A similar loop will have to be used to remove a user from a role.  This avoids having to trap an exception that gets thrown when the user cannot be found in the role collection.

    Update:  I found this post.  Take a look.

    --Mark

  • How To Retrieve a User's Profile in SharePoint 2003

    I am currently building a Web Part for our internal SharePoint 2003 portal site that will return the employee directory complete with photo, email address, and home, work, and cell phone numbers. To do this, the web part needs to access to the users profile. Here is the C# code needed to get the user profiles. 

    *The below code does not represent a complete web part*

    First, make sure that your web part has the appropriate code access security settings such as the SharePointPermission with the following setting: ObjectModel=True. For more information on Code Access Security and SharePoint, click here.

    Add the following using statements after the assemblies are referenced.

    using Microsoft.SharePoint.Portal;
    using Microsoft.SharePoint.Portal.Topology;
    using Microsoft.SharePoint.Portal.UserProfiles;
    The root site will have to be retrieved to get the collection of users. Use the following method to get the base URL.

    private string GetRootUrl()
    {

    string url = Context.Request.Url.GetLeftPart(UriPartial.Authority) + this.ResolveUrl( Context.Request.ApplicationPath);
    return url;

    }

    *NOTE* If you are accessing the portal site via http://localhost/, you must add http://localhost/ as an alias for the site.

    //Get the root URL and the PortalContext.
    string url = GetRootUrl();
    SPSite rootSite = SPControl.GetContextSite(Context);
    PortalContext portalContext =
    null;
    Uri uri =
    new Uri(url);

    //Get the collection of portal sites by the URL.
    TopologyManager topologyManager = new TopologyManager();
    PortalSiteCollection sites = topologyManager.PortalSites;
    portalContext = PortalApplication.GetContext(sites[uri]);

    //Get all the users that have access.
    SPUserCollection allUsers = rootSite.RootWeb.AllUsers;
    UserProfileManager upm =
    new UserProfileManager(portalContext);

    //Loop through the users to get their profile.
    foreach (SPUser user in allUsers)
    {

    //Do whatever needs to be done with the following properties.
    UserProfile up = upm.GetUserProfile(user.LoginName);

    string fullName = up["PreferredName"].ToString();
    string emailAddress = up["WorkEmail"].ToString();
    string homePhone = up["HomePhone"].ToString();
    string cellPhone = up["MobilePhone"].ToString();

    }

    To see a list of property names available to you, navigate here: Site Settings > Manage profile Database > View profile properties.

    For additional resources on SharePoint, visit the following sites:

    SharePoint and Code Access Security
    Lamont Harrington's SharePoint 2003 Resource Center
    SharePoint University
    Push the Limits of SharePoint Customization

    --Mark

  • Fifty Invites from GMail

    Today Paul pointed out that GMail has given us 50 invites to give away.

    I don't know about the rest of you, but I have had a hard time giving away the sets of six that GMail gave out in the past.

    --Mark

More Posts Next page »

Our Sponsors

Free Tech Publications

This Blog

Syndication

News