Archive

Author Archive

Rituals

September 27, 2011 2 comments

Respecting somebody’s genuine feelings is more than enough a reason to follow rituals you may not necessarily want to.

Categories: Brain Munch

C# word automation : Inserting page break

May 30, 2011 Leave a comment

I went through many articles in order to insert a page break in word document with C#. Though they seemed to work for others, they did not for me. But I did find a way to insert breaks.

object oEndOfDoc = "\\endofdoc";
object paramNextPage = WdBreakType.wdSectionBreakNextPage;

wrdDocument.Bookmarks.get_Item(ref oEndOfDoc).Range.InsertBreak(ref paramNextPage);

WHERE
wrdDocument
- Active word document object of type : Microsoft.Office.Interop.Word.Document

Categories: .NET

C# Word Automation: Inserting images with text wrapping around

March 9, 2011 3 comments

As I work, I keep noting about my work here. Earlier, I wrote about inserting images in a word document at a bookmark in this post. Later, arose the need for having text wrapping around an image if it is small for document width. Solution is to use frames to achieve it and here is how I did it.

CImage class definition:

    public class CImage
    {
        public string Path
        {
            get;
            set;
        }

        public decimal Id
        {
            get;
            set;
        }

        public string Title
        {
            get;
            set;
        }

        public Image Bitmap
        {
            get;
            set;
        }

        public bool BusyLoading
        {
            get;
            set;
        }

        public void GetImage()
        {
            try
            {
                BusyLoading = true;
                WebRequest req = WebRequest.Create(Path);
                WebResponse response = req.GetResponse();
                Stream stream = response.GetResponseStream();

                Bitmap = Image.FromStream(stream);
                
                stream.Close();
            }
            catch
            {
                Bitmap = null;
            }
            finally
            {
                BusyLoading = false;
            }
        }

 
        public override bool Equals(object obj)
        {
            CImage objToCompare = obj as CImage;
            if (objToCompare == null)
                return false;
            return this.Id.Equals(objToCompare.Id);
        }
    }

Adding frame at end of the document (can be any bookmark for that matter)

Frame wrdFrame = wrdDocument.Frames.Add(wrdDocument.Bookmarks.get_Item(ref oEndOfDoc).Range);

WHERE
wrdDocument
- Active word document object of type : Microsoft.Office.Interop.Word.Document

Setting frame properties for textwrap and autosize

wrdFrame.TextWrap = true;
wrdFrame.VerticalDistanceFromText = 7;
wrdFrame.HorizontalDistanceFromText = 10;
wrdFrame.HeightRule = WdFrameSizeRule.wdFrameAuto;
wrdFrame.WidthRule = WdFrameSizeRule.wdFrameAuto;

Inserting image in frame

Clipboard.SetDataObject(objImage.Bitmap);
wrdFrame.Range.Paste();

WHERE
objImage
- Object of type CImage

And you are done !

Important information

You need to add a COM reference to your favorite word object library which should in turn add

Related Posts
Categories: .NET

Anticipating TortoiseSVN 1.7 Beginner’s Guide

March 4, 2011 Leave a comment

Yesterday, I got an email from Zaid Siddiqui, Packt Publication asking to review their book Tortoise SVN 1.7 Beginner’s Guide by Lesley Harrison. And I agreed instantly being curious and experimental about SVN related stuff and Tortoise SVN being an important part in the whole scheme of things.

Before I start reading any book, I like to anticipate the experience it may offer me by it’s cover, title, and preface. This time of course it is no different and I thought i might as well write it down to check later what I got and what I did not.

By the sound of it’s title, I am really looking forward to using this book as a recommendation to a fresh out of college hired developer on team. I usually get really hard time explaining them why we do certain things with tortoise SVN the way we do. After some experience, they follow commonly used instructions and panic when they see something like a conflict for a file. Some of them actually did a revert without even giving it a second thought out of panic. Since this book is for beginners, I would really like to introduce a rule – look in this book if you have doubts and before taking any action [and before giving me a hard time ;) ].

Second role I would like this book to play in my life as a process specialist is of a my personal desk copy – helping me get instant answers to problems I face in daily operations especially managing various versions and releases for various sizes of projects.

Security is another aspect I would like to get insights in. But that probably would be better covered as server part than tortoise SVN. Anything on that would certainly be delicious.

That much for now. Let’s see what I get after going through this book.

Categories: SVN

C# Word Automation : How to add a Shape textbox

March 3, 2011 3 comments

Though I took quite a lot of time to figure it out; when I did – it actually seemed pretty simple !

Shape wrdTextBox = wrdDocument.Shapes.AddTextbox(
Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
0, 2, 500, 30, ref objRange);

WHERE

wrdDocument
- Active word document object of type : Microsoft.Office.Interop.Word.Document

objRange
- Range object in wrdDocument where I want this text box to be inserted of type : Microsoft.Office.Interop.Word.Range

 

In order to assign text and style to this text box:


wrdTextBox.TextFrame.TextRange.Text = "I am sitting right inside a textbox in word";
wrdTextBox.TextFrame.TextRange.set_Style(ref my_style);

 

 

Important information

You need to add a COM reference to your favorite word object library which should in turn add

Related Posts
Categories: .NET

SVN : Preparing for branching/ Merging process

February 3, 2011 4 comments

Preparing your repository for branching and merging can turn into a headache when you do it for the first time. This is a small .. may be obvious .. note to everybody who can get some help

My setup

  • SVN Server hosted on linux
  • Tortoise SVN as client being used from windows

If you perform following checks before getting into the process of branching and merging, you are going to save a lot of time and efforts trying to figure out errors messages and causes

  1. Make sure your SVN Server version is above 1.5. If not, UPGRADE. In my case it was 1.4.2 and I upgraded it to 1.6.* from Collabnet
  2. Make sure your SVN Repository version is upgraded. You can find that out by using following commands
    cd /path/to/repo/reponame
    cd db
    cat format
    

    i.e. changing to repo/directory/db and looking at contents of format file. For 1.4.*, format file showed 2, which should be 4 for it to be a 1.6.* repository. I had to upgrade the repository version by using
    svnadmin upgrade path/to/repo/reponame
    
  3. Make sure your SVN Client is equipped to handle features offered by the upgraded SVN Server. I just downloaded version of tortoise svn made for 1.6 version

After these checks, you can choose the model you want to opt for your process and get started.

In my case, I chose mainline development happening in trunk, creating branches after each phase release. Every-time a bug is fixed in a branch, its committed to its corresponding branch. Then from trunk, using TortoiseSVN’s “reintegrate a branch” option, I choose repository URL of branch and follow through steps to finish the merge. It works wonders !

Related posts

Categories: Linux, SVN

SVN : Utility commands

February 3, 2011 4 comments

List of SVN utility commands that I needed to use frequently apart from commit and update. Feel free to add to the list

  • Know SVN binary path
    which svn
    
  • Know SVN server version installed
    svnadmin --version
    
  • Know SVN Client server version installed
    svn --version
    
  • Create SVN Respository
    svnadmin create path/to/repository/reponame
    

    You can then assign permissions to reponame directory like you do on any other directory
  • Upgrade SVN Respository version
    svnadmin upgrade path/to/repository
    

Related posts

Categories: Linux, SVN

C# Word Automation: Solve “The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)”

December 29, 2010 5 comments

Assignment:
Export data in word 2003 format using COM Interop

Problem:
First time export worked just fine. Second time, I received exception “The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)” for “Microsoft.Office.Interop.Word”

Solution:

  
public class CDocumentExporter
{
        static ApplicationClass _word_application;

        public static ApplicationClass AppClass
        {
            get
            {

                if (_word_application == null)
                {
                    _word_application = new ApplicationClass();
                    _word_application.ApplicationEvents2_Event_Quit += new ApplicationEvents2_QuitEventHandler(_word_application_ApplicationEvents2_Event_Quit);
                }
                return _word_application;
            }
        }

        static void _word_application_ApplicationEvents2_Event_Quit()
        {
            _word_application = null;
        }
}//end of class

And just use the CDocumentExporter.AppClass wherever necessary

Important information

You need to add a COM reference to your favorite word object library which should in turn add

Related Posts
Categories: .NET

C# Word Automation: Inserting Images

December 23, 2010 3 comments

I was looking for a way to insert images at a bookmark in a word document and thought should document these for future reference

CImage class Definition

public class CImage
{
        public string Path
        {
            get;
            set;
        }

        public decimal Id
        {
            get;
            set;
        }

        public string Title
        {
            get;
            set;
        }

        public Image Bitmap
        {
            get;
            set;
        }

        public bool BusyLoading
        {
            get;
            set;
        }

        public void GetImage()
        {
            try
            {
                BusyLoading = true;
                WebRequest req = WebRequest.Create(Path);
                WebResponse response = req.GetResponse();
                Stream stream = response.GetResponseStream();

                Bitmap = Image.FromStream(stream);
                stream.Close();
            }
            catch
            {
                Bitmap = null;
            }
            finally
            {
                BusyLoading = false;
            }
        }
}

Scenario 1:
You have a path of the image file which is to be inserted

public static void SetBookMark(Document p_objWordDocument, string p_strName,
          CImage p_objImage)
        {
            if (p_objWordDocument.Bookmarks.Exists(p_strName))
            {
                object objBookMark = p_strName;
                p_objWordDocument.Bookmarks.get_Item(ref objBookMark).Range.InlineShapes.AddPicture(p_objImage.Path, ... dozons of object params ...);
            }
        }

Scenario 2:
When you have the bitmap in memory

public static void SetBookMark(Document p_objWordDocument, string p_strName,
           CImage p_objImage)
        {
            if (p_objWordDocument.Bookmarks.Exists(p_strName))
            {
                object objBookMark = p_strName;
                Clipboard.SetDataObject(p_objImage.Bitmap);
                p_objWordDocument.Bookmarks.get_Item(ref objBookMark).Range.Paste();
            }
        }

Important information

You need to add a COM reference to your favorite word object library which should in turn add

Related Posts
Categories: .NET

Brain munch: Money

March 5, 2010 Leave a comment

Money is a toy introduced by mankind for mankind to be engaged for lifetime.

Categories: Brain Munch
Follow

Get every new post delivered to your Inbox.