A Developer Journey who codes for fun

Daily Dose Of Code

  • Home
  • Dot.Net Basics
    • .Net Basics
      • CTS
      • CLS
      • CLR
      • Strong Vs Weak Ref
      • .Net Framework
      • What is Manifest
    • Memory Management
      • Garbage Collection 1
      • Garbage Collection 2
      • Circular Reference
  • C Sharp
    • Abstract Class in C#
    • Interfaces in C#
    • Value type by Val and By Ref
    • Var keyword
    • Null Coalescing Operator
    • Buit-in code snippets
  • OOPS
    • Abstraction and Encapsulation
    • Polymorphism
    • Inheritence
    • Aggregation
  • Threading
    • Delegates
      • Calling Delegate using Invoke, BeginInvoke
      • Multicast Delegate
      • Exception Handling in Multicast Delegate
      • Action
      • Predicate
      • Func
    • Synchronization
    • Thread Pool
    • Exception Handling
    • TPL
  • Design Pattern
    • Creational Patterns
      • Singleton Pattern
      • Factory Pattern
      • Abstract Factory Pattern
      • Prototype Pattern
      • Builder Pattern
    • Structural Patterns
      • Adapter Pattern
      • Bridge Pattern
      • Composite Pattern
      • Proxy Pattern
      • Facade Pattern
      • Decorator Pattern
      • Flyweight Pattern
    • Behavioral Patterns
      • Command Pattern
      • Interpreter Pattern
      • Iterator Pattern
      • Mediator Pattern
      • Memento Pattern
      • Observer Pattern
      • State Pattern
      • Strategy Pattern
      • Visitor Pattern
      • Chain Of Responsibility Pattern
      • Template Pattern
  • Data Structures
    • Generic List in C#
    • 2d array to 1d array
    • 3d arrayto 1d array
    • Linked List
      • Singly Linked List in C#
    • Queue
      • Dummy Data 1
    • Stack
      • Dummy Data 2
    • Tree
      • Dummy Data 3
    • Graph
      • Dummy Data 4
  • WCF
    • WCF Service using VS 2015
  • Scripts
    • Chrome Extensions
      • Create a Chrome Extension
      • Facebook autologout script
      • Gmail autologout script

File System Watcher in C#(Get notified after any modification)

 Unknown     7:26 AM     No comments   

Drag FileSystemWatcher control in your form from toolbox and add the events for created,deletion and renaming.
Ex:-
#region Designer view

this.fileSystemWatcher.EnableRaisingEvents = true;
this.fileSystemWatcher.IncludeSubdirectories = true;
this.fileSystemWatcher.SynchronizingObject = this;
this.fileSystemWatcher.Created += new System.IO.FileSystemEventHandler(this.fileSystemWatcher_Created);
this.fileSystemWatcher.Deleted += new System.IO.FileSystemEventHandler(this.fileSystemWatcher_Deleted);
this.fileSystemWatcher.Renamed += new System.IO.RenamedEventHandler(this.fileSystemWatcher_Renamed);
public System.IO.FileSystemWatcher fileSystemWatcher;

#endregion
Create three bool variables to set true or false :-
#region Properties
private bool _fileDeleted = false;
private bool _fileRenamed = false;
private bool _fileCreated = false;

public bool FileDeleted
{
set
{
_fileDeleted = value;
}
get
{
return _fileDeleted;
}
}
public bool FileRenamed
{
set
{
_fileRenamed = value;
}
get
{
return _fileRenamed;
}
}
pblic bool FileCreated
{
set
{
_fileCreated = value;
}
get
{
return _fileCreated;
}
}
#endregion

#region EventHandlers

private void fileSystemWatcher_Renamed(object sender, RenamedEventArgs e)
{
_fileRenamed = true;
MessageBox.Show(e.Name + " Renamed in " + e.FullPath);
}
private void fileSystemWatcher_Deleted(object sender, FileSystemEventArgs e)
{
_fileDeleted = true;
MessageBox.Show(e.Name + " Deleted in " + e.FullPath);
}
private void fileSystemWatcher_Created(object sender, FileSystemEventArgs e)
{
_fileCreated = true;
MessageBox.Show(e.Name + " created in " + e.FullPath);
}

#endregion

By this property if you want to check file has been removed ,deleted from physical path then this will be true and you can check like if you have a tree view and you dont want to repopulate your tree view then use filesystemwatcher and repopulate the tree only when files have been changed,delete or rename. or you can throw a messagebox like above.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

String Functionality of C# (Play with strings)

 Unknown     7:01 AM     No comments   

1:- Convert string to LowerCase
public static String Lower(String constantString)
{
return constantString.ToLower();
}
2:-Convert String to UpperCase
public static String Upper(String constantString)
{
return constantString.ToUpper();
}
3:- Convert String to proper case
public static String PCase(String constantString)
{
String strProper=constantString.Substring(0,1).ToUpper();
constantString=constantString.Substring(1).ToLower();
String strPrev=string.Empty;

for(int iIndex=0;iIndex < constantString.Length;iIndex++)
{
if(iIndex > 1)
{
strPrev=constantString.Substring(iIndex-1,1);
}
if( strPrev.Equals(" ") ||
strPrev.Equals("\t") ||
strPrev.Equals("\n") ||
strPrev.Equals("."))
{
strProper+=constantString.Substring(iIndex,1).ToUpper();
}
else
{
strProper+=constantString.Substring(iIndex,1);
}
}
return strProper;
}
4- Function to Reverse the String
public static String Reverse(String constantString)
{
if(constantString.Length==1)
{
return constantString;
}
else
{
return Reverse(constantString.Substring(1)) + constantString.Substring(0,1);
}
}
5- Function to Test for Palindrome
public static bool IsPalindrome(String constantString)
{
int stringLength,halfLength;
stringLength=constantString.Length-1;
halfLength=stringLength/2;
for(int iIndex=0;iIndex<=halfLength;iIndex++)
{
if(constantString.Substring(iIndex,1)!=constantString.Substring(stringLength-iIndex,1))
{
return false;
}
}
return true;
}
6- Function to get string from beginning.
public static String Left(String constantString,int iLength)
{
if(iLength>0)
return constantString.Substring(0,iLength);
else
return constantString;
}
7- Function to get string from end
public static String Right(String constantString,int iLength)
{
if(iLength>0)
return constantString.Substring(constantString.Length-iLength,iLength);
else
return constantString;
}
8:-Function to count no.of occurences of Substring in Main string
public static int CharCount(String sourceString,String stringToCount)
{
int count=0;
int position=sourceString.IndexOf(stringToCount);
while(position!=-1)
{
count++;
strSource=sourceString.Substring(position+1);
position=strSource.IndexOf(stringToCount);
}
return count;
}
9:-Convert arrayList to string[]ArrayList subKeysColletion = new ArrayList();
string[] collectionOfSubkeys = new string[subKeysColletion.Count];
collectionOfSubkeys = subKeysColletion.ToArray(typeof(string)) as string[];
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Create customize OpenFileDialogBox and SaveFileDialogBox using shell

 Unknown     3:31 AM     No comments   




The Open dialog box lets the user specify the drive, directory, and the name of a file or set of files to open.

The Save As dialog box lets the user specify the drive, directory, and name of a file to save.

Explorer-style Open and Save As dialog boxes provide user-interface features that are similar to the Microsoft Windows Explorer. However, the system continues to support old-style Open and Save As dialog boxes for applications that must be consistent with the old-style user interface.

In addition to the difference in appearance, the Explorer-style and old-style dialog boxes differ in their use of custom templates and hook procedures for customizing the dialog boxes. However, the Explorer-style and old-style dialog boxes have the same behavior for most basic operations, such as specifying a file name filter, validating the user's input, and getting the file name specified by the user. For more information about the Explorer-style and old-style dialog boxes, Check out in the given images.

For more information check out MSDN link :---
http://msdn.microsoft.com/en-us/library/ms646960(VS.85).aspx
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Get CSIDL Code (System Index of Directories)

 Unknown     3:01 AM     No comments   

const int CSIDL_DESKTOP = 0x0000; //
const int CSIDL_INTERNET = 0x0001; // Internet Explorer (icon on desktop)
const int CSIDL_PROGRAMS = 0x0002; // Start Menu\Programs
const int CSIDL_CONTROLS = 0x0003; // My Computer\Control Panel
const int CSIDL_PRINTERS = 0x0004; // My Computer\Printers
const int CSIDL_PERSONAL = 0x0005; // My Documents
const int CSIDL_FAVORITES = 0x0006; // \Favorites
const int CSIDL_STARTUP = 0x0007; // Start Menu\Programs\Startup
const int CSIDL_RECENT = 0x0008; // \Recent
const int CSIDL_SENDTO = 0x0009; // \SendTo
const int CSIDL_BITBUCKET = 0x000a; // \Recycle Bin
const int CSIDL_STARTMENU = 0x000b; // \Start Menu
const int CSIDL_MYDOCUMENTS = CSIDL_PERSONAL; // Personal was just a silly name for My Documents
const int CSIDL_MYMUSIC = 0x000d; // "My Music" folder
const int CSIDL_MYVIDEO = 0x000e; // "My Videos" folder
const int CSIDL_DESKTOPDIRECTORY = 0x0010; // \Desktop
const int CSIDL_DRIVES = 0x0011; // My Computer
const int CSIDL_NETWORK = 0x0012; // Network Neighborhood (My Network Places)
const int CSIDL_NETHOOD = 0x0013; // \nethood
const int CSIDL_FONTS = 0x0014; // windows\fonts
const int CSIDL_TEMPLATES = 0x0015;
const int CSIDL_COMMON_STARTMENU = 0x0016; // All Users\Start Menu
const int CSIDL_COMMON_PROGRAMS = 0x0017; // All Users\Start Menu\Programs
const int CSIDL_COMMON_STARTUP = 0x0018; // All Users\Startup
const int CSIDL_COMMON_DESKTOPDIRECTORY = 0x0019; // All Users\Desktop
const int CSIDL_APPDATA = 0x001a; // \Application Data
const int CSIDL_PRINTHOOD = 0x001b; // \PrintHood
const int CSIDL_LOCAL_APPDATA = 0x001c; // \Local Settings\Applicaiton Data (non roaming)
const int CSIDL_ALTSTARTUP = 0x001d; // non localized startup
const int CSIDL_COMMON_ALTSTARTUP = 0x001e; // non localized common startup
const int CSIDL_COMMON_FAVORITES = 0x001f;
const int CSIDL_INTERNET_CACHE = 0x0020;
const int CSIDL_COOKIES = 0x0021;
const int CSIDL_HISTORY = 0x0022;
const int CSIDL_COMMON_APPDATA = 0x0023; // All Users\Application Data
const int CSIDL_WINDOWS = 0x0024; // GetWindowsDirectory()
const int CSIDL_SYSTEM = 0x0025; // GetSystemDirectory()
const int CSIDL_PROGRAM_FILES = 0x0026; // C:\Program Files
const int CSIDL_MYPICTURES = 0x0027; // C:\Program Files\My Pictures
const int CSIDL_PROFILE = 0x0028; // USERPROFILE
const int CSIDL_SYSTEMX86 = 0x0029; // x86 system directory on RISC
const int CSIDL_PROGRAM_FILESX86 = 0x002a; // x86 C:\Program Files on RISC
const int CSIDL_PROGRAM_FILES_COMMON = 0x002b; // C:\Program Files\Common
const int CSIDL_PROGRAM_FILES_COMMONX86 = 0x002c; // x86 Program Files\Common on RISC
const int CSIDL_COMMON_TEMPLATES = 0x002d; // All Users\Templates
const int CSIDL_COMMON_DOCUMENTS = 0x002e; // All Users\Documents
const int CSIDL_COMMON_ADMINTOOLS = 0x002f; // All Users\Start Menu\Programs\Administrative Tools
const int CSIDL_ADMINTOOLS = 0x0030; // \Start Menu\Programs\Administrative Tools
const int CSIDL_CONNECTIONS = 0x0031; // Network and Dial-up Connections
const int CSIDL_COMMON_MUSIC = 0x0035; // All Users\My Music
const int CSIDL_COMMON_PICTURES = 0x0036; // All Users\My Pictures
const int CSIDL_COMMON_VIDEO = 0x0037; // All Users\My Video
const int CSIDL_RESOURCES = 0x0038; // Resource Direcotry
const int CSIDL_RESOURCES_LOCALIZED = 0x0039; // Localized Resource Direcotry
const int CSIDL_COMMON_OEM_LINKS = 0x003a; // Links to All Users OEM specific apps
const int CSIDL_CDBURN_AREA = 0x003b; // USERPROFILE\Local Settings\Application Data\Microsoft\CD Burning
const int CSIDL_COMPUTERSNEARME = 0x003d; // Computers Near Me (computered from Workgroup membership)
const int CSIDL_FLAG_CREATE = 0x8000; // combine with CSIDL_ value to force folder creation in SHGetFolderPath()
const int CSIDL_FLAG_DONT_VERIFY = 0x4000; // combine with CSIDL_ value to return an unverified folder path
const int CSIDL_FLAG_DONT_UNEXPAND = 0x2000; // combine with CSIDL_ value to avoid unexpanding environment variables
const int CSIDL_FLAG_NO_ALIAS = 0x1000; // combine with CSIDL_ value to insure non-alias versions of the pidl
const int CSIDL_FLAG_PER_USER_INIT = 0x0800; // combine with CSIDL_ value to indicate per-user init (eg. upgrade)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Older Posts Home

About The Author

Unknown
View my complete profile

Total Pageviews

Popular Posts

  • Clr - Common Language Runtime
    .Net framework provides a run time environment - CLR. Common language runtime takes the IL code from the compiler( language specific) and p...
  • Auto logout chrome extension for Gmail
    Hello Friends, In the last article we learned to create a sample chrome extension. Here we are going to create auto logout Gmail script as...
  • Predicate delegate in C#
    Hello Everyone, In the article we will talk about Predicate delegate. Predicate is also a delegate which encapsulate a method that takes...
  • .Net Framework overview
    Hello friends : Here i am writing my first article on .Net framework anyways....So the question is What is .Net Framework ? The .Net fram...
  • What does it mean by disconnected data access architecture of ADO.Net?
    ADO.Net introduces the concept of disconnected data architecture. In traditional data access components, you make a connection to the databa...
  • Calling the Delegates using Invoke(), BeginInvoke() and DynamicInvoke() ?
    Hello Guys, So in the last article we talked about What is delegate and how can we create a delegate. In this article we will discuss w...
  • Nagarro Placement Papers..
    Ques.1 :- Seat Reservation prog for the theatre. Write a function for seat allocation for the movie tickets. Total no of seats available are...
  • C code to Check the string has valid identifier or not in.
    #include #include #include char keyword[][10]={"auto","break","case","char","const","...
  • Garbage Collection - Automatic memory management
    While thinking of this question few things are coming in my mind ~ How .Net reclaims objects and memory used by an application ? So the ans...
  • Delegates in C Sharp
    A Delegate is a type variable that holds the reference to a method. Delegates are similar to Pointer to functions in C and C++ When we...

Blog Archive

  • ►  2016 (4)
    • ►  September (2)
      • ►  Sep 03 (2)
    • ►  August (1)
      • ►  Aug 28 (1)
    • ►  April (1)
      • ►  Apr 24 (1)
  • ►  2015 (12)
    • ►  September (10)
      • ►  Sep 30 (1)
      • ►  Sep 29 (1)
      • ►  Sep 28 (1)
      • ►  Sep 27 (2)
      • ►  Sep 26 (3)
      • ►  Sep 20 (1)
      • ►  Sep 19 (1)
    • ►  August (1)
      • ►  Aug 16 (1)
    • ►  March (1)
      • ►  Mar 31 (1)
  • ►  2013 (10)
    • ►  June (1)
      • ►  Jun 16 (1)
    • ►  April (1)
      • ►  Apr 21 (1)
    • ►  February (8)
      • ►  Feb 18 (3)
      • ►  Feb 17 (2)
      • ►  Feb 16 (2)
      • ►  Feb 15 (1)
  • ►  2012 (1)
    • ►  May (1)
      • ►  May 27 (1)
  • ►  2010 (22)
    • ►  October (14)
      • ►  Oct 21 (1)
      • ►  Oct 06 (12)
      • ►  Oct 04 (1)
    • ►  April (2)
      • ►  Apr 22 (1)
      • ►  Apr 16 (1)
    • ►  March (1)
      • ►  Mar 30 (1)
    • ►  January (5)
      • ►  Jan 08 (3)
      • ►  Jan 01 (2)
  • ▼  2009 (110)
    • ►  December (8)
      • ►  Dec 18 (2)
      • ►  Dec 05 (1)
      • ►  Dec 04 (5)
    • ►  November (1)
      • ►  Nov 27 (1)
    • ►  October (14)
      • ►  Oct 09 (4)
      • ►  Oct 07 (1)
      • ►  Oct 06 (3)
      • ►  Oct 05 (3)
      • ►  Oct 01 (3)
    • ►  September (17)
      • ►  Sep 30 (1)
      • ►  Sep 29 (1)
      • ►  Sep 28 (1)
      • ►  Sep 25 (1)
      • ►  Sep 24 (1)
      • ►  Sep 17 (2)
      • ►  Sep 15 (3)
      • ►  Sep 11 (2)
      • ►  Sep 09 (3)
      • ►  Sep 08 (2)
    • ▼  August (31)
      • ►  Aug 31 (1)
      • ►  Aug 27 (3)
      • ►  Aug 26 (1)
      • ►  Aug 25 (2)
      • ►  Aug 24 (1)
      • ►  Aug 22 (2)
      • ►  Aug 21 (3)
      • ►  Aug 20 (2)
      • ►  Aug 19 (3)
      • ►  Aug 18 (1)
      • ►  Aug 16 (1)
      • ►  Aug 12 (2)
      • ►  Aug 11 (1)
      • ►  Aug 10 (3)
      • ▼  Aug 07 (4)
        • File System Watcher in C#(Get notified after any m...
        • String Functionality of C# (Play with strings)
        • Create customize OpenFileDialogBox and SaveFileDia...
        • Get CSIDL Code (System Index of Directories)
      • ►  Aug 06 (1)
    • ►  July (24)
      • ►  Jul 25 (4)
      • ►  Jul 24 (20)
    • ►  April (15)
      • ►  Apr 10 (3)
      • ►  Apr 07 (9)
      • ►  Apr 06 (3)

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments
copyright @ TechGiant 2015. Powered by Blogger.

Disclaimer

This is my personal blog and i write articles on .Net, WPF, C#, OOPS, Threading and other .Net technologies. This is not related to any of my employer and organizations. This is the result of my personal interest.

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Followers

Copyright © A Developer Journey who codes for fun | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com