Like this Blog on FB

Showing posts with label Microsoft. Show all posts
Showing posts with label Microsoft. Show all posts

Monday, December 13, 2010

Change the Scroll Bar Color - Silverlight



Hello Folks,

Here I hit the Bloggers' world all over again. Yes... with a technical posting.
Here is a very brief description of the problem:

The color of the silverlight scroll bar was looking very ugly in one of my projects and it needs to be changed. Am so sure that the regular, default pale scroll bars suck most of the time. But, we lazy coders never seem to care to change it. Rather we tend to compromise. When it 'NEEDS' to be changed. Please go ahead and follow the post. Few simple steps and a few minutes of time, You are done.

Tools Needed: Microsoft Expression Blend.

Time taken: 5 Mins.

When you are all set start off with this

Step 1: Open a new project in Expression Blend and drag a scroll viewer control on to the Layout.


Step 2:

o Go to Objects and timeline,

o Right click on the Scroll Viewer

o Click on Edit Template and

o Select edit a copy


Step 3: Specify a name in the Dialog Box that appears.

Step 4: Once you do so you will find the scroll viewer being made by mending many bits and pieces viz. Scroll Content Presenter, Rectangle, Vertical Scroll Bar, Horizontal Scroll Bar etc.


Now, that we have already got the individual parts. Here starts the customization part.

Step 5: Select the individual element you want to customize or change in the scroll viewer. My target now is to change the color of the scroll bar. So I select the Horizontal Scroll bar. And repeat the Step #2.

Step 6: Specify a name in the Dialog Box that appears. Make sure that you give a meaningful name and remember it to use it at a later time. Otherwise you might end up in ruckus.

Step 7: You can now see that the Horizontal Scroll bar is made of few more isolated components such as Rectangles, Horizontal Thumbs etc. The Horizontal thumb is the actual scrolling part of the scroll bar which can be moved. So our aim is to change its default color. Repeat the Step #2 on the Horizontal Thumb. In the dialog box give any meaningful name.

Step 8: Now we arrive at a destination of the real work. The thumb is made of a group of nothing but just rectangles . In order to change the basic Look and Feel of the Scroll Bar, select the “Background gradient” rectangle and navigate to the Properties window.

You can see all the colors are set to white in the Properties panel. Now unleash the designer in you and sharpen the creativity as you proceed with the next step.

Step 9: Change the colors on the gradient bar to the colors you wish to or the colors you are demanded for. You can change the no of colors and order of the colors. I now stick to 4 colors and change them to violet and shades of violet.

P.S : Change the BackgroundMouseOver Rectangle colors in the same manner. If you don’t do so your Scroll Bar looks like some south Indian comedian’s Black oily face …in short UGLY

Step 10: Click on the Return to scope and Underlined Upper Arrow button in the Objects and Timeline window(see the Image). Click the same button till you reach the Layout root level where you see the Scroll Viewer


Step 11: Now its Climax time; Apply the Edited style to the scroll viewer. Identify the scroll viewer, right click on it, and Go to Edit Template, Click Apply resource (By doing this we apply the style which we have created).

Step 12: Select the Style with the name you have specified in Step #6.

Save the application and Run it. This is how the Scroll Viewer looks like in the Browser.


You can see the Ugly and Regular Pale scroll bar in 2 and 1 is the Colorful scroll bar which we have created. Now tell me which one really Looks “ROCKING”……….!!!!

-Happy Coding


Cheers,

Sriki



Monday, May 10, 2010

Getting the UNC Path of the Network Drives using DllImport, C# and .NET Framework

Folks,
Back again. Once again I was lazy for the past month and half and was dull at the bloggers end. I have been doing more productive work for the last couple of weeks and hence there were no posts from me. However, finally I am at writing a post. People who know me closely and have moved closely with me, please hold your hearts strong because this is a head-toe technical posting and it is related to C#. Yes, finally here I go with a techie posting YAY!. Since the post is more educational I chose to use more formal 'language and format' of writing.

Problem:

One of the requirements of the product that I was doing is like this: There will be a screen in a windows based application and it consists of a combo box. The combo box should display the network drives of the computer. For those who are less literate about network drives; Network Drives are those locations that are mapped to a drive or folder in another system which can be accessed over network. Usually it is often painful to manually navigate to the network location and access the files there. So windows allows us to create network drives on our machines such that we can access the desired network location with just one single click.

How to create a Network Drive?

The creation of network drives is a very simple process.
  • Open My Computer --> Select tools from the menu bar--> Select the Map Network Drive option.
  • This opens a window which has a combo box with the existing network drives and non networking drives.
  • Upon selecting a drive the text box below the drop down list will display the path that the network is mapped to.
  • Once you select the drive letter from the combo box , Enter the Network path in the text box and click Finish.
  • Now you should be able to view the network drives in the my computer screen.

Solution to the Problem:

If you have ever worked on .NET you would certainly know how vast is the base class library of .NET. We can do many things with it. Yet, we cannot do everything using just the .NET framework and the BCL. Windows OS( XP,VISTA,WINDOWS 7) uses a special assembly called 'mpr.dll". mpr.dll is a module containing functions that are used to handle communication between the Windows operating system and the installed network providers. This assembly basically takes care of the relation between Drive Name Versus the Network Path. So we use the same .dll to fetch us the information that we need. The assembly should be referred as an external assembly and values should be passed to it. Inorder to do this we use the DllImport attribute method to point to the mpr.dll. We must point the Drive letters to the external Dll this shoud be done with the help of MarshallAs attribute.

Have a look at the following code.

namespace Srikanth.Samples
{
public static class Pathing
{
[DllImport("mpr.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern int WNetGetConnection(
[MarshalAs(UnmanagedType.LPTStr)] string localName,
[MarshalAs(UnmanagedType.LPTStr)] StringBuilder remoteName,
ref int length);
///
/// Given a path, returns the UNC path or the original. (No exceptions
/// are raised by this function directly). For example, "P:\2008-02-29"
/// might return: "\\networkserver\Shares\Photos\2008-02-09"
///

/// The path to convert to a UNC Path
/// A UNC path. If a network drive letter is specified, the
/// drive letter is converted to a UNC or network path. If the
/// originalPath cannot be converted, it is returned unchanged.

public static string GetUNCPath(string originalPath)
{
StringBuilder sb = new StringBuilder(512);
int size = sb.Capacity;

// look for the {LETTER}: combination ...
if (originalPath.Length > 2 && originalPath[1] == ':')
{
// don't use char.IsLetter here - as that can be misleading
// the only valid drive letters are a-z && A-Z.
char c = originalPath[0];

if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'))
{
int error = WNetGetConnection(originalPath.Substring(0, 2), sb, ref size);
if (error == 0)
{
DirectoryInfo dir = new DirectoryInfo(originalPath);
string path = Path.GetFullPath(originalPath).Substring(Path.GetPathRoot(originalPath).Length);
return Path.Combine(sb.ToString().TrimEnd(), path);
}
}
}
return originalPath;
}
}
}
As far as my requirement is considered I have a combo box which is currently used to display all the drives that are there in my computer. Irrespective of whether the drive is a network drive or a local drive the current combo box displays all the drives. My requirement is to only display the network drives that are available there in my system. How do I do this? Thanks to the .NET framework, the DriveInfo class of the framework allows you to search through all the drives that are available on the machine. All that I needed to do was just ,run a foreach loop which looks for the Drives which are of network type.

This is as simple as this:


DriveInfo[] allDrives = DriveInfo.GetDrives();

foreach (DriveInfo d in allDrives)
{
if (d.DriveType == DriveType.Network)
{
cmbbxDrive.Items.Add(d.ToString());
}
}

Doing this will allow me to fetch the only network drives into the combo box. Upon selecting one of the drives the Drive's Letter will be sent as a parameter(LPStr) to the MarshalAs method. The "Mpr.dll" will now do the respective task and returns us the string which is essentially the path of Network Drive and the Folder eg:"\\MyServer\MyFolder". As per the need one can split the path further and save into Database. Otherwise you can send the one who assigned you the task a message saying "MISSION ACCOMPLISHED"


Hope this is better than the love tips post!

Cheers,
Sriki

Friday, February 6, 2009

Duplicate Detection in Microsoft Dynamics CRM

Microsoft Dynamics is a CRM which is being widely used these days.

A CRM is a system that is used to manage all the business operations of a company. I have been involved in customizing the CRM for meeting the requirements of our firm. This blog entry is all about explaining the process of Duplicate detection.

One of the Business requirements that usually a company has is that - if you wish to maintain the information of Leads, then you don’t want the duplicate records of the leads to be there in the lead entity. More clearly if there is a lead with an e-Mail id say abc@xyz.com and if we are trying to add another lead with different name but the e-mail ID as abc@xyz.com then that is considered as a duplicate. Hence this scenario has to be handled. This means we should not allow the duplicate record.

In order to do this the following steps are to be followed.

· Go to SettingsàData Management à Duplicate Detection rules

· In that click on the NEW button on the top navigation bar.

· This opens a new window. In That window give the Name, base record type and matching record type and then set the attributes and criteria as per the requirement and save it using the Save and Close.

· Now the page gets navigated to the previous page.

· In this page select the rule which you want to publish and click on the Publish button.