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

How to implement a progressBar while opening a textFile in an application ?

 Unknown     3:16 AM     No comments   

Make a claas like this one to create ProgressBar :-
public class StatusProgressBar : ToolStripProgressBar
{
#region Private Fields

private static StatusProgressBar _instance = null;

#endregion

#region Constructor

private StatusProgressBar()
{
this.Style = ProgressBarStyle.Blocks;
this.Step = 1;
}

#endregion

#region Properties

///
/// Get Singleton instance of progressBar
///

public static StatusProgressBar Instance
{
get
{
if (_instance == null)
{
_instance = new StatusProgressBar();
}

return _instance;
}
}

#endregion
}

Now main issue how to increase the bar and how calculate the percentage then firstly i would say calculate numer of lines to be read or parsed in amy editor according to your application

public const char NEWLINE_CHARACTER = '\n';
string[] lines = t.Split(NEWLINE_CHARACTER);

This will perform for all the lines and lines will be incremented then progress bar will be increemented accordingly.
for (int lineIndex = 0; lineIndex < lines.Length; lineIndex++)
{
if (lineIndex % 2 == 0)
{
StatusProgressBar.Instance.PerformStep();
StatusProgressBar.Instance.ToolTipText = Convert.ToString((StatusProgressBar.Instance.Value / StatusProgressBar.Instance.Maximum) * 100) + "%";
}
}

Happy to code................
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

What is Reference counting in COM ?

 Unknown     1:56 AM     No comments   

Reference counting is a memory management technique used to count how many times an object has a pointer referring to it. The first time it is created, the reference count is set to one. When the last reference to the object is nulled, the reference count is set to zero and the object is deleted.
Care must be exercised to prevent a context switch from changing the reference count at the time of deletion. In the methods that follow, the syntax is shortened to keep the scope of the discussion brief and manageable.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

What is COM ?

 Unknown     12:51 AM     No comments   

Microsoft’s COM is a technology for component software development. It is a binary standard which is language independent. DCOM is a distributed extension of COM.
Microsoft COM (Component Object Model) technology in the Microsoft Windows-family of Operating Systems enables software components to communicate. COM is used by developers to create re-usable software components, link components together to build applications, and take advantage of Windows services. COM objects can be created with a variety of programming languages. Object-oriented languages, such as C++, provide programming mechanisms that simplify the implementation of COM objects. The family of COM technologies includes COM+, Distributed COM (DCOM) and ActiveX® Controls.

Microsoft provides COM interfaces for many Windows application programming interfaces such as Direct Show, Media Foundation, Packaging API, Windows Animation Manager, Windows Portable Devices, and Microsoft Active Directory (AD).

COM is used in applications such as the Microsoft Office Family of products. For example COM OLE technology allows Word documents to dynamically link to data in Excel spreadsheets and COM Automation allows users to build scripts in their applications to perform repetitive tasks or control one application from another.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

How can we make Windows API calls in .NET?

 Unknown     12:26 AM     No comments   

Windows API call are not COM based and they are invoked through Platform Invoke Services.StringConversionType is for what type of conversion should take place. Either we can specify Unicode to convert all strings to Unicode values, or Auto to convert strings according to the .NET runtime rules.

There are few thumbrules to make API calls :-
1:- MethodName is the name of the API to call.
2:- DllName is the name of the DLL.
3:- Args are any arguments to the API call.
4:- Type is the return type of the API call.

partial class Form1 : Form
{
[DllImport(“Kernel32.dll”)]
static extern int Sleep(long dwMilliseconds);

public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
MessageBox.Show(“Starting of 5000 ms...”);
Sleep(5000);
MessageBox.Show(“End of 5000 ms...”);
}
}
}
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

ShFileOperation not working under Wista and Windows7.

 Unknown     1:50 AM     No comments   

I've used ShFileOperation for file operations but was facing some problems and i was not able to understand then i do googling and found the 'cause' of the problems with the SHFileOperation function in Vista . It turns out that this function is not thread safe under Vista. It works fine with earlier operating systems when used in a multi threading application.

Then i got to know about IFileOPeration interface in vista, you can say a replacement of ShFileOperation.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

How to convert 2d array to 1d array ?

 Unknown     5:01 AM     No comments   

Suppose you to insert or get the values from 1d array using 2d dimensions like :-
Insert value at (1,2) and the value is 5 then you have to find the logic to get the index :-

Firstly you have to know the size of 2d array here suppose :- (2x3)

int xPosition = 1;
int yPosition = 2;

3 is ySize of 2d array.
int 1dIndex = (3*xPosition)+ yPosition ;

Insert at this index or get from this index.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

How to convert 3d array to 1d array ?

 Unknown     4:39 AM     1 comment   

Suppose you have to insert a value at (2,1,0) and the value is :-5
means firstly you have to find the index through (2,1,0) then you have to insert value 5 at that index .

Logic is :-
Firstly you must have to know the 3d array size suppose here is (3x2x3).
int xPosition = 2;
int yPosition = 1;
int zPosition = 0;

int indexOf1dArray = (xPosition *2*3) + ((yPosition * 3)+zPosition) ;

Using this insert the value at this index indexOf1dArray and if you have to get the value then again find index using this method and then find the value at this place.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

What is the difference between .ToString() and Convert.ToString() ?

 Unknown     3:40 AM     No comments   

int value = 3;
string stringConversion = value.ToString();
string stringConversion = Convert.ToString(value);

We can convert the integer “value ” using “value .ToString()” or “Convert.ToString”
The basic difference between them is “Convert” function handles NULLS .It handles null exception while “value .ToString()”does not it will throw a NULL reference exception error. So as good coding practice using “convert” is always safe.

Happy to code...
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Built-in Code Snippets (C#)

 Unknown     11:55 PM     No comments   

List of built in code snippets -

#if :- Creates a #if directive and a #endif directive.
#region :- Creates a #region directive and a #endregion directive.
~ :- Creates a destructor for the containing class.
checked :- Creates a checked block.
ctor :- Creates a constructor for the containing class.
cw :- Creates a call to Console.WriteLine.
for :- Creates a for loop.
forr :- Creates a for loop that decrements the loop variable after each iteration.
invoke :- Creates a block that safely invokes an event.
iterindex :- Creates a "named" iterator and indexer pair by using a nested class.
lock :- Creates a lock block.
mbox :- Creates a call to System.Windows.Forms.MessageBox.Show. You
may need to add a reference to System.Windows.Forms.dll.
prop :- Creates a automatic property
propg :- Creates a property declaration with only a "get" accessor and a backing field.
propfull : Creates a property with private field.
sim :- Creates a static int Main method declaration.
svm :- Creates a static void Main method declaration.
try :- Creates a try-catch block.
tryf :- Creates a try-finally block.
unsafe :- Creates an unsafe block.
unchecked :- Creates an unchecked block.

Happy to code.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

.Net Standard Date-Time-Format strings

 Unknown     11:13 PM     No comments   


Have a look on this image you will find very interesting i mentioned all the date-time format strings in this image.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Message-Box refreshing issue

 Unknown     10:34 PM     No comments   

I have used many message boxes in my current application but in some places where i used list box,list there when i move messagebox then the back screen is looks like everything is removing or cleaning nothing just refreshing issue, then i look and sort out by sinety testing like i used listView.BeginUpdate(); before dialog box check when i used after it then it works fine. because this method is used to update listview without any flicker and refreshing but i used before dialog check thats why i was facing that problem.

Happy to code...
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

How to collapse Environmental variables in a path using C# ?

 Unknown     4:39 AM     No comments   

Pass the path if there are environmental variables exist in the path then it will be collapsed into a valid path and return the valid path.
Constants :-
public const string PATH_SEPARATOR = @"\";
public const string ENVIROMENT_VARIABLE_FORMAT = "%{0}%";

public static string CollapseEnviromentVariables(string pathString)
{
string result = pathString;

if (string.IsNullOrEmpty(pathString) == false)
{
IDictionary environmentVariables = Environment.GetEnvironmentVariables();
Dictionary matchingEnv = new Dictionary();
bool isReplaceEnv = false;

foreach (DictionaryEntry environmentVariable in environmentVariables)
{
if ((pathString.Length >= ((string)environmentVariable.Value).Length) && (pathString.Contains((string)environmentVariable.Value)))
{
isReplaceEnv = false;

foreach (string matchingEnvEntry in matchingEnv.Keys)
{
if ((((string)matchingEnv[matchingEnvEntry]).Length <= ((string)environmentVariable.Value).Length) &&
((string)environmentVariable.Value).Contains((string)matchingEnv[matchingEnvEntry]))
{
matchingEnv.Remove(matchingEnvEntry);
matchingEnv.Add((string)environmentVariable.Key, (string)environmentVariable.Value);
isReplaceEnv = true;
break;
}
}

if (isReplaceEnv == false)
{
matchingEnv.Add((string)environmentVariable.Key, (string)environmentVariable.Value);
}
}
}

int matchingEnvIndex = 0;
int matchingEnvLength = 0;

foreach (string matchingEnvEntry in matchingEnv.Keys)
{
matchingEnvIndex = result.IndexOf(matchingEnv[matchingEnvEntry]);
matchingEnvLength = matchingEnv[matchingEnvEntry].Length;

//Replace environment variable only if environment variable value is enclosed by path seperators
//and matched value is found after replacing other variables.

if ((matchingEnvIndex > -1) &&
((matchingEnvIndex == 0) || (result[matchingEnvIndex - 1].ToString() == Constants.PATH_SEPARATOR)) &&
((matchingEnvIndex + matchingEnvLength == result.Length) || (result[matchingEnvIndex + matchingEnvLength].ToString() == Constants.PATH_SEPARATOR)))
{
result = result.Replace(matchingEnv[matchingEnvEntry], string.Format(Constants.ENVIROMENT_VARIABLE_FORMAT, matchingEnvEntry));
}
}
}
return result;
}
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

How to allign multiple strings using seperator in C# ?

 Unknown     4:20 AM     No comments   

Constant file.public const char SYMBOL_SPACE_CHARACTER = ' ';

public static List AlignText(string[] strings, char seperator)
{
List formattedStringList = new List();
List ListOfCommaSeperatedStringsInLine = new List();
string[] commaSeperatedStringsArray = null;
List maxColumnWidthArray = new List();

//split strings into list of comma seperated array of strings and calculate maximum length of string array.
foreach (string str in strings)
{
commaSeperatedStringsArray = str.Split(seperator);

//remove all trailing and leading spaces.
for (int index = 0; index < commaSeperatedStringsArray.Length; ++index)
{
commaSeperatedStringsArray[index] = commaSeperatedStringsArray[index].Trim();

//initialize maximum characters in each column.
if (maxColumnWidthArray.Count > index)
{
maxColumnWidthArray[index] = (maxColumnWidthArray[index] < commaSeperatedStringsArray[index].Length) ? commaSeperatedStringsArray[index].Length : maxColumnWidthArray[index];
}
else
{
maxColumnWidthArray.Add(commaSeperatedStringsArray[index].Length);
}
}

ListOfCommaSeperatedStringsInLine.Add(commaSeperatedStringsArray);
}

StringBuilder formattedString = new StringBuilder();
int accumlativeMaxLength = 0;
int pad = 0;

//Insert spaces to align text and append in single line text.
foreach (string[] stringsInLine in ListOfCommaSeperatedStringsInLine)
{
formattedString.Append(stringsInLine[0]);
accumlativeMaxLength = maxColumnWidthArray[0];

for (int index = 1; index < maxColumnWidthArray.Count; ++index)
{
if (stringsInLine.Length > index)
{
pad = accumlativeMaxLength - formattedString.Length;
formattedString.Append(seperator);
formattedString.Append(Constants.SYMBOL_SPACE_CHARACTER, pad);

if (IsNumeric(stringsInLine[index]))
{
formattedString.Append(Constants.SYMBOL_SPACE_CHARACTER, maxColumnWidthArray[index] - stringsInLine[index].Length);
}

formattedString.Append(stringsInLine[index]);
accumlativeMaxLength += maxColumnWidthArray[index] + 1;
}
}

formattedStringList.Add(formattedString.ToString());
formattedString.Length = 0;
}

return formattedStringList;
}
This is very useful method when you have to align certain strings and there is a seperator then this method will allign all the lines, just pass the array of strings and a seperator.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

How to check invalid characters in path using C#

 Unknown     3:26 AM     9 comments   

If you create a new folder then there are some characters which are not allowed and any thing in which user have rights to create path then firstly check the invalid characters otherwise your application or program will through an exception.

Pass the path or string for which you have to check.
public static bool CheckInvalidCharacters(string path)
{
bool invalidCharacters = false;

if (string.IsNullOrEmpty(path) == false)
{
char[] invalidChars = Path.GetInvalidFileNameChars();

foreach (char invalidChar in invalidChars)
{
if (path.Contains(invalidChar.ToString()))
{
invalidCharacters = true;
break;
}
}
}
return invalidCharacters;
}
This will return a bool variable if path or string contains invalid characters then it will return true else false.
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

  • 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...
  • 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...
  • 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...
  • 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...
  • .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...
  • 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...
  • 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...
  • How to convert 3d array to 1d array ?
    Suppose you have to insert a value at (2,1,0) and the value is :-5 means firstly you have to find the index through (2,1,0) then you have to...

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)
        • How to implement a progressBar while opening a tex...
        • What is Reference counting in COM ?
        • What is COM ?
        • How can we make Windows API calls in .NET?
      • ►  Oct 07 (1)
        • ShFileOperation not working under Wista and Windows7.
      • ►  Oct 06 (3)
        • How to convert 2d array to 1d array ?
        • How to convert 3d array to 1d array ?
        • What is the difference between .ToString() and Con...
      • ►  Oct 05 (3)
        • Built-in Code Snippets (C#)
        • .Net Standard Date-Time-Format strings
        • Message-Box refreshing issue
      • ►  Oct 01 (3)
        • How to collapse Environmental variables in a path ...
        • How to allign multiple strings using seperator in ...
        • How to check invalid characters in path using C#
    • ►  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)
      • ►  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