" Live as if you were to die tomorrow. Learn as if you were to live forever.. "
- Mahatma Gandhi

How to create Floating Palette in Acrobat or Photoshop plug-in

Posted on November 24th, 2015 by Divya Jain

To Create a floating palette in Acrobat/Photoshop plugin two simple steps are needed –  use CreateDialog() and ShowWindow() along with SDK specific floating palette flag (if any needed).   First Step is to create palette by using CreateDialog(). // Get the parent window HWND here. either use your SDK API’s or WIN32 API’s HWND hParent […]

How to draw custom shaped cursor without using an image?

Posted on November 24th, 2015 by Divya Jain

We can customize our cursors in almost every Adobe software. Generally we do so by providing a beautiful image for our custom cursor. In Acrobat, In addition to customize the cursor, we can draw different shapes in cursor view at run time. For example: if we want to our cursor to look like a cross […]

How to Get the List of Printer(s) Installed on a Machine in C#

Posted on November 24th, 2015 by Rashmita Devi

We can get the list of Printer(s) installed on a particular machine by using the following method. First of all we have to use the “System.Drawing.Printing” namespace. PrintDocument and PrinterSettings classes are present inside this namespace. Using these classes we can easily get the list of Printer(s). private bool GetPrinterList() { bool retVal = false; PrintDocument […]

MidPointRounding for Math.Round() method in .Net Application

Posted on November 24th, 2015 by Rashmita Devi

We all know Math.Round() basically rounds a particular decimal value. But if we look into this method closely it rounds the value to the nearest even value. For example if we do Math.Round(2.5,0) it will return 2. But we may expect 3 intead of 2. In that case we can use MidPointRounding parameter of Math.Round() […]

Using extension methods in C# to make your code reusable

Posted on November 24th, 2015 by Shantanu Gupta

We often have to write a function to clear the content of a form on submit button-click. But the same thing can be done reusing the few lines of code in other parts of the project and overloading it to add more and more functionalities. public static void ClearTextAndSelection(this Form frm) { foreach (Control ctrl in frm.Controls) { if (ctrl.GetType() […]

Set default printer using C#.NET [VS 2008]

Posted on November 24th, 2015 by Amrita Dash

Following is the code sample used to set the default printer. We need to add the reference of “System.Management” to the project.   [C#.NET CODE STARTS] // namespace declaration using System.Management; // code sample for setting default printer ManagementObjectCollection objManagementColl; // class used to invoke the query for specified management collection ManagementObjectSearcher objManagementSearch = new […]

Extending Microsoft Commerce Server Web Services in C#

Posted on November 23rd, 2015 by Nirmal Hota

Microsoft Commerce Server makes use of web services to perform the e-commerce business transactions as well as other associated functionality along with the inventory and marketing. There are mainly 4 webservices as follows: 1. Catalog Webservice – Responsible for the Products and inventory management 2. Marketing Webservice-Resposible for the management of advertisements,discounts etc 3. Order […]

How to store C++ object pointers in Core foundation’s ordered collections like CFMutableArrayRef, CFMutableDictionaryRef.

Posted on November 23rd, 2015 by Mithlesh Jha

We create a new mutable array object using the function CFArrayCreateMutable which has following signature: CFMutableArrayRef CFArrayCreateMutable( CFAllocatorRef allocator, CFIndex capacity, const CFArrayCallBacks* callBacks);    Where the first parameter gives the type of allocator used to allocate memory for this array, second gives its capacity and third parameter is a pointer to CFArrayCallBacks structure which […]

How To Start writing CUDA Program

Posted on November 23rd, 2015 by Kundan Kumar

1. Who can start CUDA programming? – Any one who has some basicknowledge on C programming. No prior knowledge of graphics programming. – CUDA is C with minimal extension and some restrictions.( CUDA is C for GPU) 2. If you have a algo that you want to write in CUDA then follow the below steps. […]

Detecting Memory leak in Visual Studio (Debug mode)

Posted on November 23rd, 2015 by Manjunath G

Microsoft Visual Studio (2003/2005) informs about memory leakes in a module by setting the “leak check” bit, _CRTDBG_LEAK_CHECK_DF, to the debugger. The memory leak information is printed on “Output” window. [ This advantage is in “Debug” mode only. ] Example int _tmain() { int* ptr = NULL; ptr = (int*)malloc(sizeof(int)*20); for( int i=0; i<20; ++i […]

Interprocess Communication using named pipe.

Posted on November 23rd, 2015 by Lipika Chatterjee

Interprocess Communication (IPC) is a set of methods for the exchange of data among multiple threads in one or more processes. IPC has four general approaches: Shared memory. Messages. Pipes. Sockets. Pipes are basically files that reside in memory instead on disk. Writing to a pipe and reading from a pipe is in FIFO manner. […]

Usage of Extension Methods in C# 3.5

Posted on November 23rd, 2015 by Satyadeep Kumar

Introduction: C# 3.0 provides a new feature called Extension Methods.  Extension methods are methods that can be added to previously defined classes without rebuilding/compiling those classes. Process: To define an extension method, we first define a static class, Then we define our static method which is meant to be extended. The first parameter of the […]

Validating a String in C#

Posted on November 23rd, 2015 by Manaswinee Mohapatra

While working with strings we may have some invalid characters within that string. So below is the code for parsing the string value and getting the filtered and correct string.  Here I am checking for the ASCII value of each character present in the string and adding them to the return value if it is […]

How to start ,stop a service in C#

Posted on November 23rd, 2015 by Abhay Raut

We can start and stop a service programmatically using C#. Basically, we need a service name and service startup type that we have to provide to start or stop. Here i will give an example to start a service. private void StartService() { System.ServiceProcess.ServiceController[] allService = System.ServiceProcess.ServiceController.GetServices(); foreach (System.ServiceProcess.ServiceController s in allService) { if (s.ServiceName.Equals(“Alerter”)) […]

Override ToString() method in C#

Posted on November 23rd, 2015 by Satyadeep Kumar

Any Object that derives from System.Object implements a method ToString() which upon calling, return the fully qualified name of the class. We can override the ToString() method to return more meaningful Results For ex: Let’s have a console application with a class called Customer, defined like: class Customer { public Customer(string firstName, string lastName, string […]

How To Iterate the Hashtable in C#

Posted on November 23rd, 2015 by Amit Pratihari

Generally when we use the collections in C# , we use the object for iteration. Example ArrayList list = new ArrayList(); list.Add(“india”); list.Add(“bharat”); foreach (object gg in list) { Console.WriteLine(“Value is ” + gg); Console.Read(); }   But in case of Hashtable it is little bit different. If we write in the same way as […]

Uses Of Params Modifier In C#

Posted on November 23rd, 2015 by Amit Pratihari

While using the function member, any numbers of parameter (including none) may appear in the calling function based on need. So to have a flexible function we can use params modifier while writing the definition of functions. The params keyword specify a method parameter that takes an argument where the numbers of arguments become variable […]

Implicitly typed local variable in C# 3.0

Posted on November 23rd, 2015 by Amit Pratihari

C# 3. 0 has introduced a new  keyword “var” which allows us to declare a new variable. As we were previously writing int x = 100; string y = “fortunate”; But now with the keyword var, we can write like this var x = 100; var y = “fortunate”; In this case the type is […]

How to take screenshot programmatically and mail it in C#

Posted on November 23rd, 2015 by Premananda Das

You can use this code to save the screenshot when there will be any possibility of error in the application .If the client is using the application developer can ask the client to send the screenshot so that he can know in which page the error was occured   To take the screenshot Bitmap bitmap […]

A single step solution to avoid Deadlock in Multi-threading

Posted on November 23rd, 2015 by Rabinarayan Biswal

In its simplest form, deadlock occurs when each of two (minimun two) threads try to acquire a lock on a resource already locked by another. E.g: Take example of two threads 1. thread 1 2. Thread 2 And two resources 1. Resource 1 2. Resource 2 Thread 1 locked on Resources 1 and tries to […]

List directory files of specific size (Using C# and LINQ)

Posted on November 23rd, 2015 by Satyadeep Kumar

The following code can be used to extract files that are greater than 1MB under any specific directory (using LINQ). private static void GetFiles(string Path) { try { DirectoryInfo directory = new DirectoryInfo(Path); FileInfo[] files = directory.GetFiles(“*.*”, SearchOption.AllDirectories); var query = from file in files where file.Length > 1024*1024 select “File Name:”+ file.Name + ” […]

Document merging in C#.NET

Posted on November 23rd, 2015 by Shantilaxmi Patro

Some times during application development we need to generate a MS Word document from a predefined format and some custom data. The predefined format is generally called as Template. This template used to carry some merge fields which can be replaced with the user data. The user data can be taken from DB or XML […]

Using NULL-COALESCE Operator in C#

Posted on November 23rd, 2015 by Rabinarayan Biswal

To my knowledge perhaps the least used operator in C# is the null-coalescing operator . But you can use it effectively to reduce the lines of code you write . The null-coalesce operator can be used to define / return a default value for a nullable value type / reference type and this is represented […]

Be Careful while dealing with dynamic type and System.DBNull in C# 4.0 (beta)

Posted on November 23rd, 2015 by Satyadeep Kumar

C# 4.0: Provides many new, useful and powerful features. One of those is “dynamic” type. “You can have a number of references with search keyword [Dynamic Type: C# 4.0 ]. I love to use it. I was facing a particular situation while executing sql statement (particulary returning a scalar value) and then returning the result. […]

Loosely typed C#

Posted on November 23rd, 2015 by Aditya Acharya

What :  A loosely typed programming languages is typically one that does not require the data type of a variable to be explicitly stated. Example : As in JavaScript we can declare var count = 1;  which will automatically treat variable count as integer. Advantage: The advantage of loosely typed is that we don’t have […]

Search/Delete files using wildcards in a directory and its sub-directories

Posted on November 23rd, 2015 by Smruti Sahoo

To demonstrate how to search and delete files of a specific extension in a particular directory and its sub-directories, let us carry out the following exercise: Take two TextBoxes and Two Button Controls. 1. txtFolderPath :-  this textbox allows user to specify which directory  (and its subdirectories) shouls be seached. 2. txtFileExtension :- this textbox […]

Run System Commands From C# | Mindfire Solutions

Posted on November 23rd, 2015 by Narendra Mallik

Sometimes we need to run some system commands from  within our program. In such cases the following example can be helpful. <%– Button in aspx file –%> <asp:Button ID=”btnCommand” runat=”server” Text=”Button” onclick=”btnCommand_Click” />     If you click on the button the following event handler will be called and the command line interface would be […]

Unsafe Keyword And Pointers In C Sharp

Posted on November 23rd, 2015 by Narendra Mallik

C# does not support pointer arithmetic by default to have type safety and security. If we want to use pointers in C# we need to use the keyword unsafe. We can have pointer types, value types and reference types in an unsafe context. When we declare multiple pointers in a single declaration, the * is […]

Create Dynamic Objects at runtime using Reflection

Posted on November 23rd, 2015 by Satyadeep Kumar

Sometimes there is a need to create duplicateinstances of a same class ( objects with same values for the properties, and fields. ) When the class is of known type,  it’s easy to duplicate the instances. For e.g.: Consider a class called MyClassExample Class MyClassExample { public int NUMBER1 {get; set;} public int NUMBER2{get; set;} […]

How to exclude empty array (null value) while using String.Split Method

Posted on November 23rd, 2015 by Tushar Mishra

A string can be split into an array of strings using String.Split() method. It returns a string array that contains the substrings of this orignal string instance that are delimited by elements of a specified character. Let us suppose an user input field is filled in an irregular manner with more than a single space […]

Interesting C# functions and their usage

Posted on November 23rd, 2015 by Devi Das

I have faced some situations earlier in which something was getting done by looping though data structures but i wanted to overcome that. Then in process of avoiding those looping, i came to know some interesting and helpful functions in C#. These are: Select() function: How to convert a string array to an integer array? […]

Two ways to use “using” keyword in C#

Posted on November 23rd, 2015 by Chittaranjan Nahak

In C#,  using Keyword  can be used in two different ways and are hence referred to differently.  As a Directive In  this usage, the “using” keyword can be used to include a namespace  in your programme.(Mostly used) As a Statement Using can also be used in a block of code to dispose a IDisposable objects.(less […]

Using Keywords as Identifiers in C#.NET

Posted on November 23rd, 2015 by Sibabrata Dash

In C# We cannot use a Keywords as an Identifier since the former is predefined and has special meaning to the compiler whereas an identifier is user-defined. However, we can use a keyword as user-defined identifier by appending “@” (at) or “_” (underscore) characters. For example: if we write Class class //Conflict error   It […]

Random Unique Code Generator

Posted on November 23rd, 2015 by Sukant Shekhar

Challenge: I was given a scenario in which i need to represent a large number by few character it must be hard to break the code. For ex: A 8 digit number into 5-6 character. That too uniquely identified per number (i.e code corresponding to each number should not match the code corresponding to different […]

Using Yield Keyword in C#

Posted on November 23rd, 2015 by Amit Mohapatra

 Yield is a keyword which is used to get list of  items from a loop. The method implementing yield keyword returns an enumerable object.Yield retains the state of the method during the multiple calls. That means yield returns a single element to the calling function and pause the execution of the current function. Next time […]

How to Create a XML File Using C#

Posted on November 23rd, 2015 by Kabita Patra

This tip demonstrates how to create XML file using C#   StringWriter stringwriter = new StringWriter(); XmlTextWriter xmlTextWriter = new XmlTextWriter(stringwriter); xmlTextWriter.Formatting = Formatting.Indented; xmlTextWriter.WriteStartDocument(); xmlTextWriter.WriteStartElement(“root”); xmlTextWriter.WriteStartElement(“information”); xmlTextWriter.WriteElementString(“FirstName”, “First Name”); xmlTextWriter.WriteElementString(“LastName”, “Last Name”); xmlTextWriter.WriteEndElement(); xmlTextWriter.WriteEndDocument(); XmlDocument docSave = new XmlDocument(); docSave.LoadXml(stringwriter.ToString()); //write the path where you want to save the Xml file docSave.Save(@”c:\Information.xml”);   Output […]

Read and Write Data to Resource File Programmatically

Posted on November 23rd, 2015 by Pallavi Praharaj

Following are the step by step process to create, read and write into resource file using code. 1.Open a new project in c# . 2. Add a ResourceFile.resx in the project. 3. Add a new class and name it as ResourceCreator 4. Add these following namespaces: using System.Windows.Forms; using System.Resources; using System.Drawing; using System.IO; 5.Add […]

Using JSON Extension Methods in WCF Service

Posted on November 23rd, 2015 by Tanveer Singh

Recently i was writing a WCF Service which would be returning me result in JSON Format. I noticed I have to write this code everytime I have to convert the data into JSON strings. How did I avoid repetetive task? By using extension Methods The code I was using before discovering extension methods  is given […]

How To Implement Extension Method In C#

Posted on November 23rd, 2015 by PRADEEP PENTAPATI

Extension method is a new feature is available in C# 3.0 compiler onwards. I’m going to explain how to add extension method in c#. I have a third party dll called “VehicleFeature.dll” and it will return the exterior features of the vehicle. VehicleExteriorFeature vehicleFeature = new VehicleExteriorFeature(); exteriorFeatue = vehicleFeature.GetExteriorFeature(2012, “BMW”, “new bmw”); In the […]

DataTable Column to Array

Posted on November 23rd, 2015 by Amrita Dash

Here is an easy way to convert a column of datatable to a 1 -dimensional array without for loop.   [C# Code Starts] string[] arrEmpName; DataRow[] rows = dtEmployees.Select(); arrEmpName = Array.ConvertAll(rows, row => row[“EmpName”].ToString()); [C# Code Ends]    

Reading datetime value from Excel cell using C#

Posted on November 23rd, 2015 by Amrita Dash

Excel stores the datetime value as a serial number.The date January 1, 1900 is treated as day 1 and all the date and time values are calculated accordingly. Also excel saves the time value as a fractional number from 0 to 1. So the date part is a whole number and time is the fractional […]

SSL Secure connection testing

Posted on November 23rd, 2015 by Amrita Dash

Here is a query to test whether the ODBC connection to MySQL database using SSL certificates is securely done. Even if, in the ODBC manager we set the SSL certificates in the details tab,to confirm that the connection is securely done we can use the following query :   [query] “show status like ‘Ssl_cipher'” [query] […]

Iterate thorugh collection for unique values only (using LINQ and C#)

Posted on November 23rd, 2015 by Satyadeep Kumar

Sometimes we work with collections that contain duplicate data and we just want to iterate over unique values inside the collection. To iterate only through unique values, we generally have to use for-loop and check (compare) each and every data inside the collection for duplicate entries, which is a bit tedious task. However, if you are using Linq it becomes […]

NextResult() in C# or ADO.NET data reader

Posted on November 23rd, 2015 by Sumit Singh

In a application if  you wants to take data from two table which have no relation to each other.At this situation you write two separate SQL query to take data from data base there is a work around to take data from multiple table in single a query.   In this sample code below: I want […]

Using MARS technique in C#.NET 2.0

Posted on November 23rd, 2015 by Rasmita Mohanty

MARS (Multiple Active Result Set) is a new concept in Visual Studio 2005. MARS means we can work with the same reader without closing the opened reader. This means opening and closing the connection for each time use of a DataReader is no longer a requisite   Suppose we take a SqlDataReader object in our […]

How to change the default template of class file in C#

Posted on November 23rd, 2015 by Nirmal Hota

Step 1 : Copy the zip file from C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip and paste this some where in the harddrive. Path may vary from machine to machine depending upon the .net  version and installation path.   Step 2:  Unzip the class.zip. You can find a Class.CS file inside the folder. This is the default template file […]

Using For loops and Foreach loop

Posted on November 23rd, 2015 by Narendra Mallik

We deal with collections and arrays almost everyday while writing programs and most of the time we need to iterate through all the elements present in an array or a collection. We normally use either for loop or foreachloop when it comes to iteration. From ease point of view while using these two types of looping we […]

Few Tips on C#/.Net

Posted on November 23rd, 2015 by Satyadeep Kumar

Few useful tips for C#/.NET 1. Nullable Types/Nullable Modifier(?):  We cannot directly assign “null” value to “Value-Type”. For this purpose nullable types has been introduced in C# 2.0.  using this we can assign null to “Value-Type” variables. For ex:     int? num = null; A nullable type has two members: HasValue: It is set to true when […]

Verbatim String Literal in Asp.Net

Posted on November 23rd, 2015 by Aditya Acharya

Many times, using long strings in our asp.net code becomes a little uncomfortable but often it becomes necessary to add long strings in our code (like SqlQuery, custom message …) . This is not a problem from the language point of view, dividing them into different lines and concatenating them either using string concatenation or […]

Filtering out the collection using Predicate argument in ASP.NET

Posted on November 23rd, 2015 by Aditya Acharya

MSDN Says : Predicate<T> delegate Represents the method that defines a set of criteria and determines whether the specified object meets those criteria. We can use this functionality when filtering any collection object which satisfy certain condition. Here is an example how to use it in our application. In this example we will see different […]

A better way to Clear a StringBuilder

Posted on November 23rd, 2015 by Santosh Bisoyi

Since .NET Framework[2.0 or 3.5] does not provide the “Clear” Method for StringBuilder class, sometimes as a developer you may come accross a sitution like using the StringBuilder object for concatenation operation of some sets of random number of string and then empty it and again re-use it for another concatenation operation. So there are […]

How to make a Downloadable XML file using c#, asp.net

Posted on November 23rd, 2015 by Sudhansu Prusty

Many times we need to export our data in xml format, but writing the xml data to a predefined xml file already included  can cause concurrency problem  for multiple users accessing the same file, also it is not a good idea to generate xml file with multiple names in the  server as it will overload […]

[c++] – Evaluating execution times

Posted on November 23rd, 2015 by Jyothi Sambolu

Lets say we have more than two solutions for a complex workflow or a workflow that includes I/O operations.And we want to find out the one that takes minimum execution time.The following simple time functions may help us in making a decision. C++ :  clock_t  clock(void) ,  CLOCKS_PER_SEC This function returns number of clock ticks elapsed between the […]

Trimming Float Value | Mindfire Solutions

Posted on November 23rd, 2015 by Manjunath G

Some times we may need a float value 2.345 instead of complete float value 2.345768. In such cases we need to trim the float value.The function below demonstrates how it can be done..   function name: trimFloat( ) param1: float f; the original float value , i.e., 2.345768 param2:int decimals; how many number of digits […]

Intensity Calculator | Mindfire Solutions

Posted on November 23rd, 2015 by Chinmay Mandal

Sound intensity is the measure of amplitude at a particular instance of time from a 16 bit .wav file. This is a sample program to demonstrate the calculation of intensity. Step 1: Read the input wav file AVIStreamOpenFromFile (PAVISTREAMobj,lpszWavFilePath,streamtypeAUDIO,0, OF_READ, NULL)) Step 2: Get the raw stream data AVIStreamInfo (PAVISTREAMobj,objAVISTREAMINFO,sizeof(objAVISTREAMINFO)) Step 3: Read stream format […]

How to efficiently allow decimal values in a Edit control in MFC

Posted on November 23rd, 2015 by Hem Dutt

Suppose we need to enter some float values in UI. If we set “Number” property of Edit control true then it will not allow to enter “.” and hence we can not enter a float value. On the other hand if we allow string then we need to check all possibilities of the characters in […]

Handling _HAS_ITERATOR_DEBUGGING and _SCURE_SCL macro on windows platform

Posted on November 23rd, 2015 by Vivek Kumar

It is very common in C++ development to use multiple third-party libraries in a single project. Recently I have faced one problem while dealing with Standard Template Library related things. Microsoft Visual C++ have added one extension to STL for checking iterator and validation. And in visual studio 2005 and 2008 this preprocessor macro is […]

Create and Update Views Programmatically in SharePoint

Posted on November 23rd, 2015 by Kaushik Mohanty

In SharePoint, View is a virtual representation of a set of data from a specific list. We can programmatically create and update views for a list. Provided below is an example in C#.Net which explains the approach of creating and updating views. The code is divided in to 2 parts i.e. Part I – describes […]

Add Choice Field Programmatically to a SharePoint List

Posted on November 23rd, 2015 by Kaushik Mohanty

Choice fields are often used within SharePoint lists to display choice options like Gender, Status, etc and these choice options can be displayed using Radio Button and Dropdown formats. Provided below is a code sample in C#.Net which describes the creation of a choice field programmatically using SharePoint API. /* get the newly added choice […]

Fetching associated groups for a User in SharePoint using Web Service

Posted on November 23rd, 2015 by Saroj Dash

At some point of time there might be a requirement to access a SharePoint site programmatically and list the names of all the groups a user is associated to without using SharePoint APIs. Here is a small piece of code in C# which demonstrates how to achieve the above action using web service(s) available for […]