Monday, June 21, 2010

How to open and Edit MSoffice document from C#.Net

Lots of people asking me how to open and edit MSoffice document from C#.Net.
Here i am giving you the way.

May you know all these and if have any better solution then comment me.

1. For just launching word. ( No need to specify the path of word exe)

2. For launching word with specifying file name.
Process.Start("Winword.exe", "My.doc");

If you want to create, edit any document file from C# Then follow these steps.

1.  From Add reference add a COM reference.
2.  Select "Microsoft Word 11.0 Object Library" Type lib version 8.3.
     ( It will vary upon library installed on your system)
     If you want to open and Edit Access, Excel files then add their respective libraries.
3. Now use the classes given by API for operating with files.

Here is a sample for word file..

using Microsoft.Office.Interop.Word;
ApplicationClass WordApp = new ApplicationClass();
   object _fileName = "My.Doc";
   object _readOnly = false;
   object _isVisible = true;
   object missing = System.Reflection.Missing.Value;
   WordApp.Visible = true;

   //the number of parameter on open method will vary according to referenced object library version
   Document aDoc = WordApp.Documents.Open(ref _fileName, ref missing, ref _readOnly, ref missing, ref missing, ref missing, ref missing, ref                                   missing, ref missing, ref missing, ref missing, ref _isVisible, ref missing, ref missing, ref missing, ref missing);

Wednesday, June 9, 2010

Free Online Exam / Certification

Hello Friends,
After a long time i am again here with some new topic.
Today i am giving you some Free Online Exam link which are very helpful for certification and you knowledge.

Even i am also doing the same way to update myself.

If you have anymore link just comment me i will post over here.

1. RankSheet:-  for .Net, java, Sql and all
2. TestWorld:- for Microsoft, Cisco, Sun and all
3. JavaBlackBelt:- for java and some editors

Wednesday, March 31, 2010

.Net Obfuscator for securing your source code

Hi Everyone,

The first priority and biggest challenge for any software developer is, How to secure application from re-engineering?

We know that the languages which are Interpreted can easily be re-engineered via Decompiler.
Even .Jar, .Class, .dll and .exe files can easily be decompiled which are created by Java and .Net.

What is Obfuscation?
Is the process of encrypting your .Net code so that it cannot be easily re-engineered.
It is language neutral technology even you can obfuscate java code too.
It is mainly used in managed languages because they can be re-engineered.

Then how to protect???

You can use Obfuscator for that. It just mangle your method, properties, classes and variables.
It means it change the name suppose your class name is Test, after obfuscator it may become ?dsghd.

So it cannot be easily understandable after decompilation.

Here i am putting some tools for protecting you code.

Wednesday, February 17, 2010

Convert Jar to Exe and Secure Java Application

Hello Friends,

Hope you will see my previous post regarding the same.

first of all Thanks for mailing me and your doubts.
Many people ask me question which one is best,secure and easy among them.

Actually many of them are developed on java itself.
So some time they just change the name of jar file to exe and it looks that we made it,
But originally you can extract it by changing its name again.

Best is use some commercial tool or Use tool which actually convert it into Win32 exe's.
I tried Excelsior that is commercial (think made in java) and jstart32 (Made in delphi) with
GNU license are tool which originally created a Win32.exe.

go and try...

Hope now you will feal secure.
Ask if any query or comment if you like.

Saturday, January 30, 2010

Accessing Master Page Properties from Child Page

 Hello Friends.

Today hot topic is that how to access properties from MasterPage into content page.
I think there is several methods you can access those properties or variable.

1. By Master property of content page
2. By interface
3. By Including a MasterPage Directive in Pages.

So here i am providing you some code stuff for the same.
1. Access Master Page properties and Method by Master property of Page.

Master Page Code

     public string ButtonText
           get { return this.Button1.Text; }
           set { this.Button1.Text = value; }

Child Page Code

        //Master page is the name of master page file
        MasterPage mast = this.Master as MasterPage;
        if (mast != null)
            mast.ButtonText = "New Text";

2. Access Master Page properties and Via Interface.
see here

Wednesday, January 27, 2010

Setting the wallpaper from C# code

Hi Friends,

What if you want to change the wallpaper of your desktop from C#.Net. for that you have to use Unmanaged code.

You have to import and pass parameters to function from User32 dll.
Here I am posting the code for performing the same.

[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern int SystemParametersInfo(int Action, int Param, string lParam, int WinIni);
call the function and pass some useful parameters like ...
Bitmap bmp = new Bitmap(Image.FromFile(@"C:\mytest.jpg"));
bmp.Save("MyFile.Bmp", ImageFormat.Bmp);
SystemParametersInfo(20, 0, "pic.bmp", 0x1);

The first parameter 20 is for Wallpaper
Third parameter is your file path as String.
Last is Update parameter keep it 0X1, 0X01 | 0X02 ..

Note:- Here you see that I am converting the jpeg file into bmp file. Because it state that image should be 24 bits, so keep in mind the change of file else no effect of this function.

Wednesday, January 20, 2010

Handling Null value in case of value type.

Hello friends,

As we can check for null values in case of Reference type.
What if want to do the same with value type.
Here the new feature of .net do it for you.

public int? x;
public int? X
get { return x; }

Now you can check
if( X != null) or if ( X == null)

Note:- Needed to be type cast to (int) where need int value.
Use:- Very usefull suppose you declared any field as integer in database table.
And you forget to declared default value as 0 (zero).
Then whenever you query to database you get a null value so it can be used for checking that.

Private setter for public getter

Hello Friends,

Now i am showing you some very good features of Net 2.0 over .Net 1.0.
Suppose you want to expose a public property. So for that you have
public getter method but what about its setter method.
from .net 2.0 tou can have a private setter for a public getter too like this.

private int x;
public int X
get { return x; }
private set { x = value; }

Monday, January 11, 2010

Creating Non-Rectangular Form in C#

Hello Friends,

Now here i am trying some very good stuff on
The first in this row is creating non rectangular Form in C#.

The Idea comes when i was created Magnifier as a sub part of my project.
When i created a rectangular magnifier it's ok but when it comes to rounded then
i have to think.

From some book i get these idea (also available in many of GDI tutorials).

The idea behind this is that, GDI provides a new Class called GraphicsPath.
With the help of this class you can draw any closed arc, lines and shapes.

So either override onPaint event of form or Onload event put some code stuff like this.

System.Drawing.Drawing2D.GraphicsPath myShape = new System.Drawing.Drawing2D.GraphicsPath();
myShape.AddEllipse(0, 0, this.Width, this.Height);
this.Region = new System.Drawing.Region(shape);

Note:- You are not getting region property directly in intellisence because it is the
property of control class and here this refers the control.

Now in place of AddEllipse you can add any closed shape for your form.
Hope you enjoy....