Like this Blog on FB

Showing posts with label Ebooks. Show all posts
Showing posts with label Ebooks. Show all posts

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

Wednesday, February 10, 2010

Valentines Day Pravachan By SRIKI Baba

Hiya Friendz,

I have questioned myself recently...
What am I blogging and Why am I blogging??? LOL...
I thought Blogging just another way to reflect my persona.
I noted that I have been doing lot of preaching,teaching stuff and Yes all this messages I deliver are more generalized.
Any group of people can visualize himself as a reader of the post.
On this note, I have decided that I should seriously post something which is Specialized.
Something which is specific to some group of people.

After all I am not a baba to preach elders.
I am a just another young chap who has lot of dreams and dreamgalz who arrive often in those dreams......
Besides, you are not supposed to deliver speeches and make suggestions in those fields in which you lack experience.
Finally, I have decided to post a blog entry in that area I am well versed.

FLIRTING.........

I am not going to say how flirting can be done or something that related to...... Because I preserve that to be a topic of my research(Ph.D). Though I deny it often.. I have lot of friends who are GIRLS( This doesnt mean that I have Girl Friends in the Indian Sense).... and I used to hang out at Ladies Hostel in HCU I was always "flocked by girls around me" ( Bold, Underlined, Italics) as said by one of friends(I am not going to reveal HER name until her permission) which made me understand the un-understandable entity to a little extent. So, I guess that will be of a little help in delivering this post.

Unfortunately, without any reason for the hells sake I had a nickname called LG(Love Guru) and I have never done any justice to the nickname/title. So, I am trying my level best to suggest you some tips for a Happy Valentines Day.
  • Look your best. Invest in some new clothes, or some swanky new gadget. Look uber cool and have the right attitude.

  • Girls don't come calling. Well that is a myth, these days, sometimes, they do. But we do not want to take chances right? So let them know that you are available. How will you do that? A single status on the social networking sites help. Easier still, let it slip to a couple of girls in your team, under the oath of secrecy of course, that you do not have a partner, and trust me, it will get you the desired result if she knows about some girl who may like being with you!

  • If there is someone you have always had a crush on, this is the right time to connect with them. Call them up, leave a message, and if you get lucky, there is nothing to beat it. A Valentine's Day spent with someone you can't connect with is even worse than one spent alone.

  • Send out sweet 'will you be my valentine' message to some random mobile numbers. Someone may respond, if you have a wrong number you can always excuse yourself, but if by any chance your message is delivered to someone equally lonely, why not push your luck a wee bit. Some such 'wrong number' calls have the history of ending up in marriages!

  • Hit at your friends- friends. Well, we don't want to make it sound shady. But consider this – your best buddy may have a girl friend and she would have a friend who is not committed. Try hinting that you would like to accompany her – plan a double date – after all she is single isn't she?

  • Social networking sites have opened up new vistas. Explore, spend time on it. Look up ex-flames and crushes on these sites. Who knows when you could turn lucky?

  • If you are the type who loves dogs, find one to take out for a walk. The cuter the dog the better, girls have a weakness for men who does this. If you don't have a dog and are sure where to find the girl, trust me, it is not bad to borrow a friend's dog for this purpose. Just make sure that the dog does not bite you or the girl!

  • Stalk. It is not a crime, everything is fair in love and war remember? At the cafeterias, cafes, shopping malls. If the universal thumb rule for love is correct, there should be someone some where made just for you. And you can't just ignore the fact that she may be at these places. And once you have shortlisted some, make sure you speak in you phone, loud enough for them to hear, 'Dad, I m not interested in an arranged marriage, I ll get married to someone I like,' and give her a sheepish grin.

  • If none of these work, no hard feelings, love will happen to you in due course. Till then, you can just have a ball and indeed there is nothing stopping you from throwing a 'single's' party at home. And hope someone may turn up, who is just right for you!

So keep hoping, Keep Loving, Keep Flirting.......

After all who said that Valentines day is just for lovers....... It is a day equal for the Flirters too.
Happy Valentine's Day Guys...............( Yes...........I mean it.......JUST GUYS).

Cheers,
SRIKI aka L G



Tuesday, January 5, 2010

Ray of hope ....... a must read poem when you are down.

This is a poem that inspired me some years ago when I was more of an Immature, Stubborn kid.
My aunt Ramakka who has been a constant source of inspiration and support for me has sent me a stanza of this poem. My ignorance and Illiteracy with the English has drawn me back from understanding the true essence to the greatest extent possible. Nevertheless I could remember the lines so perfectly "Let eyes grow dim and heart go faint".

Time has flown downstream in the form of days, months and years together and I have developed a better maturity on contrast with my prior years. I dont claim now that I am a flawless human being. Because the fact is that there are no thing that exists like "Flawless" in humans and thus we are called humans. If at all there are some so called flawless humans they are not termed as flawless humans but 'GOD'. However, even after being sufficiently matured enough to tackle many types of people with diverse mindsets around in the day to day life I come across, I often fail to handle certain situations. Situations that challenge me in every walk of my life. Being having a Never Never give up kind of attitude I feel molested, teased and frustrated if I cannot solve the Zigsaw. On one of the recent days when I was feeling so down for some lame reason which tamed me so badly. I lost myself in rediscovering those days of my life where I was a warrior and won many battles with the life. Suddenly during the self talk of mine, I reminded a poem which can be called as a flash of hope in the uttermost darkness.

Swami Vivekananda has been a Role Model for many people and his words are confidence pumping for each one on this planet. Here is the full version of the poem that have stamped my heart and left its mark on it. I remember certain words of the poem till now ;Which I think essentially means that it has been inspiring m right from the day one I read it. Hopefully this helps many other people like me who are searching for a hand, a star of hope to lead their way in the path of prosperity.

The wounded snake its hood unfurls,
The flame stirred up doth blaze,
The desert air resounds the calls
Of heart-struck lion's rage.

The cloud puts forth it deluge strength
When lightning cleaves its breast,
When the soul is stirred to its in most depth
Great ones unfold their best.

Let eyes grow dim and heart grow faint,
And friendship fail and love betray,
Let Fate its hundred horrors send,
And clotted darkness block the way.

All nature wear one angry frown,
To crush you out - still know, my soul,
You are Divine. March on and on,
Nor right nor left but to the goal.

Nor angel I, nor man, nor brute,
Nor body, mind, nor he nor she,
The books do stop in wonder mute
To tell my nature; I am He.

Before the sun, the moon, the earth,
Before the stars or comets free,
Before e'en time has had its birth,
I was, I am, and I will be.

The beauteous earth, the glorious sun,
The calm sweet moon, the spangled sky,
Causation's law do make them run;
They live in bonds, in bonds they die.

And mind its mantle dreamy net
Cast o'er them all and holds them fast.
In warp and woof of thought are set,
Earth, hells, and heavens, or worst or best.

Know these are but the outer crust -
All space and time, all effect, cause.
I am beyond all sense, all thoughts,
The witness of the universe.

Not two nor many, 'tis but one,
And thus in me all me's I have;
I cannot hate, I cannot shun
Myself from me, I can but love.

From dreams awake, from bonds be free,
Be not afraid. This mystery,
My shadow, cannot frighten me,
Know once for all that I am He.

- Swami Vivekananda



Cheers,

Sriki

Thursday, September 24, 2009

The Lost Symbol Novel by Dan Brown Download link

Dan Brown is one of those finest authors of English who has written 4 books till now. I have read three of them till now!
The Da Vinci Code being the first flick from him. The Davinci Code has created a controversy amongst the Catholic community but finally has won many accolades.

Digital Fortress is the most favorite book of mine- this is the second flick from Dan.This is such a superb page turner that you cant wait a second to keep the book aside. The story revolves around a Superficial, fictitious Computer called TRANSLTR and the code that is needed to stop the computer from burning out.

Deception point is the third novel which narrates the superficial existence of PODS and a Huge rock beneath a Glacier. The suspense he maintained throughout the novel will make you simply say aaaah!!.

Fourth book that DAN wrote is titled Angels and Demons. This book was a blast too and this has also made it to Hollywood and hit the screens worldwide with unbelievable graphics.

I have been waiting for over an year for Dan to release the next novel of him- The Lost Symbol.The lost symbol has created loads of enthusiasm amongst the followers of Dan. The very website that is created for promoting the book was tremendous Here is the link of the site http://www.thelostsymbol.com/. However, as many things come to an end, my waiting for Lost Symbol has also come to an end and finally the book got released lately.

The Lost Symbol is now available all over the world (YAY!!!!). To people who are lethargic like me who cannot go to a store and buy a copy of that - I want to help you in getting a soft copy of the book downloaded directly. I could successfully download the book and started reading it.


For all the folks, here is the link to download the Multi format Version of this Book.
In case if you are not able to access the link , Copy paste this URL in your browser.
http://hotfile.com/dl/13203785/8591b6b/DBTLS-Multiformat.rar.html

The book is available in .pdf,.html, and a SQL server replication snapshot Procedure script. The PDF is the easiest and very user friendly format. So, if you are a Dan Brown fan Download the files and terminate the enthusiasm you have been facing for so looooong. If you are not a fan, even then download a copy and start reading it .I bet you will love it. He is such a good fiction storyteller that many a times while reading his books you take away your breath.

I would like to complete the book As soon as possible and write a review on it later.
Till then adios, ciao, hasta la vista',


Have fun and Keep rockin'!

Cheers,
Sriki

Thursday, June 25, 2009

EBook Download Heaven.

Hello Guys...

Here is a link that I have been using for the past 2 years to download all my favorite English Books. Mainly Novels. This site has a Very big range of Novels ranging from the Old books to the New ones. It also provides you a series ( Like Trilogy etc.,) in one single Zip or Rar File. For instance you can find all the Bourne Series of Robert Ludlum in one single .rar file.

The name of the site seems to be weird. But Never mind .. As long as it serves a good cause ... All Hail this site.

Here is the Link for unrestricted Downloading.

Have fun.


Cheers,
Sriki

Thursday, October 2, 2008

My fav sentences from Alchemist

The Alchemist is a wonderful novel written by Paulo Coelho.
This novel is all about a boy who travels across countries to realize his dream.
Though this Novel is fictitious- it also has a dash of romance added at some point of time and a small conversation says...

"I'm going away," he said। "And I want you to know that I'm coming back. I love you because…"

"Don't say anything," Fatima interrupted. "One is loved because one is loved. No reason is needed for
loving."



When a person really desires something, all the universe conspires to help that person to realize his
dream," said the alchemist..

This sentence is re used in the Bollywood Movie- any guesses??
Om shanti Om.

किसी चीज़ को पूरे दिल से चाहो तोह पूरे कायनात उसे तुझसे मिलाने की कोशिश करती हैं !!!.....





There are many more sentences that impressed me ..will post them later.




as of now.....

Say Cheese....

Sriki