Is Excel Present in client machine?

by munnaonc 16. August 2010 21:36
In one of our application we had to make sure that whether client have excel installed or not. We tried few codes and have some experience while resolving the solution. Bello the solution code is given to detect if client have excel 2007 installed or not.
 
The bellow code works fine. But it fails one single time. If the user installed excel but never run it. The registry keys are not built until the user run excel for the first time. so we had to change our message to inform user as “You don’t have excel or you didn’t run it after install, if you have install please run it for the first time and try again” some thing like this.
 
private static bool IsExcelPresent()
{
var key = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Office");
if(key!=null)
{
string[] subKeyNames = key.GetSubKeyNames();
if(subKeyNames.Contains("12.0"))
{
var excelKey = key.OpenSubKey("12.0\\Excel\\");
if(excelKey!=null) return true;
}
else
{
return false;
}
}
return false;
}

 
Eventually we got rid of the obstacle and found a very interesting component called SpreadsheetGear and used that component. we bypassed all the excel requirement using this component.
 
There are some more solutions on the web to you guys can also try those. Bellow a yet another code sample is given.
 
private static bool IsExcelPresent()
{
try
{
Type officeType = Type.GetTypeFromProgID("Excel.Application");
return officeType != null;
}
catch (Exception ex)
{
return false;
}
}

Another code sample to detect excel which using registry key search
 
private static bool IsExcelPresent()
{
RegistryKey key = Registry.ClassesRoot;
RegistryKey excelKey = key.OpenSubKey("Excel.Application");
bool excelInstalled = excelKey == null ? false : true;
return excelInstalled;
}



Using the Build event of visual studio 2008

by munnaonc 21. September 2009 20:09

Background

Some times we need to execute some custom task just before we build our solution or project, I have no idea how others IDE do that, but recently we have gathered some experience about Visual Studio 2008, and doing these kind of task became pretty easy.

In one of our project we had to use a custom third-party component, the component is easy to incorporate in the project, but we have a problem, the component uses a d-com component which can not be added in the project, but if we keep the com component in bin directory the program runs okay. so our challenge is to copy the component before build in the bin directory of output project from the other projects bin.

Visual Studio 2008 Build Events

In Visual studio 2008 we have two build event, prebuilt event command and post build event command, post build event can be controlled with various parameters for example, post build event will raise when a successful build is happened.

image  

Figure: Visual Studio 2008 Build tab under Project properties

In our particular case we solved our problem in using pre-build event, now let us discuss a little bit more about pre-built event, you can use almost any kind of command in command line, provided that the commands don't require special permissions for executions.

In our case we have used "xcopy" command to solved the problem, there are lot of macro for execution. we used target directory as output macro, and source directory as solution macro, since its a simple problem we set the relative path of the DLL from solution path. worked okay, when we published the project we found that in publish version also contains the DLL, job done with very good time and in a good way.

Post build is almost similar like pre-build except it has some extra control, user can specify when to raise it, in the above screen shot you can see that there is a large combo at the bottom.

Here is a small example command in the for pre-build command.

If we want to copy all output files of a project to a deployment folder after post build event we have to put down the following command in the post build command line,

""xcopy "$(TargetDir)*.*" "c:\output" /S /I /F <NUL:""

Bellow i have put down a pre-build event command line input window with macro.

image

well that's all for now, please visit the references for more information, best of luck and happy coding.

References

  1. http://msdn.microsoft.com/en-us/library/42x5kfw4.aspx
  2. http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx
  3. http://dotnetperls.com/post-pre-build-macros
  4. http://skysanders.net/subtext/archive/2009/09/05/visual-studio-2008-build-event-xcopy-bug.aspx

Wpf Image ,Working with Image Source

by munnaonc 1. June 2008 19:28

Hi after a long time I am back in my blog. In this post I will discuss few things about WPF image object. Recently I have been working in a project whose UI Layer is build entirely with windows presentation foundation.

Background

WPF has another way to display image. That is, using BitmapImage object. You can declare BitmapImage tag and in WPF XAML just like Image tag. But in case of BitmapImage the source property is a Uri name is UriSource. Luckily BitmapImage is the source property of Image. Here is a simple code segment of Image and BitmapImage.

ImageSource & BitmapImage

WPF has another way to display image. That is, using BitmapImage object. You can declare BitmapImage tag and in wpf xaml just like Image tag. But in case of BitmapImage the source property is a Uri name is UriSource. Luckily BitmapImage is the source property of Image. Here is a simple code segment of Image and BitmapImage

<Image Width="200" Margin="5" Grid.Column="1" Grid.Row="1" >
<Image.Source>
<BitmapImage UriSource="sampleImages/bananas.jpg" />
</Image.Source>
</Image>

Mouse hover effect

Bellow I have listed few lines of code when i change the image in mouse enter and mouse out of an image object. Of course I am using Uri to define the location of my image then using the Uri to make a new BitmapImage and finally use BitmapImage to assign Image.Source Property.

   1:  private void btnGoToHome_MouseEnter(object sender, MouseEventArgs e)
   2:  {
   3:      this.Cursor = Cursors.Hand;
   4:      Uri src = new Uri(@"C:/Images/DifferentTransaction_Icon_Active.png");
   5:      BitmapImage img = new BitmapImage(src);
   6:      btnGoToHome.Source = img;
   7:  }
   8:  
   9:  private void btnGoToHome_MouseLeave(object sender, MouseEventArgs e)
  10:  {
  11:      this.Cursor = Cursors.Arrow;
  12:      Uri src = new Uri(@"C:/Images/DifferentTransaction_Icon_Normal.png");
  13:      BitmapImage img = new BitmapImage(src);
  14:      btnGoToHome.Source = img;
  15:  }

Thats it you are done

Reference

http://msdn.microsoft.com/en-us/library/system.windows.controls.image.aspx

Creating web application and web site that run in IIS 7 of windows vista from vs2008

by munnaonc 28. January 2008 18:17

While creating a web site in vs2005 or vs2008 , web site location has three options and the options are 1. File System 2. HTTP 3. FTP

image

Previous version of Visual studio (VS2002,VS2003) supports web application that run only on IIS. User can easily create web applications cause Visual Studio automatically guide the user to create a web application. Since vs2005 come with whole new application suite for example, Web Site template , web application template and mix mode of Ajax templates user had options to chose between many things. I personally used IIS and File System web site and web applications (File System web run on Vs integrated vs development web server ) in windows XP. I have recently moved to windows vista and and VS2008 Team System. I found some interesting stuff regarding windows vista and vs2008 that I thought need little share with the community (might help some one).

Web site in VS2008 on windows vista that run on IIS

image

I wanted to create a web site in IIS so I opened vs2008 selected ASP.net "Web Site" project template and Choose Local IIS but I found a strange message and unable to proceed to create a virtual directory from the wizard. I didn't read the message carefully, I thought my IIS is not installed properly or my IIS is not running. I opened my IIS administration MMC from administrator tool and found that IIS is up and running well, then I got confused and performed the same site creation operation again. This time when the Local Internet Information Server tab got selected I read the message carefully and it says how to create web site from vs2008, and it says I got to run vs2008 with "Run as administrator" :)

image

I closed my IDE and opened IDE from start menu with "Run as administrator" options selected from right click menu and performed the same operation again, this time every thing worked just okay :).

image

Web app in VS2008 on windows vista that run on IIS

While creating a "web application" project (which is created via choosing new project, rather than new web site from File->New menu) user do not have any option to select between File system or IIS hosted project in project creation wizard. By Default a File System based web application is created for the user. Just follow the normal procedure to create a web application, after web application creation is completed select the project properties. When the project properties window appear select the Tab named "Web*". You will see in web tab by default "Use Visual Studio Development Server" option is selected. change it to "Use IIS Web Server" option. After that just click on the Create Virtual Directory button to finish the procedure. save the project and you are good to go.

image

Oh one more thing, for this operation, again you have to run IDE in Run as administrator mode.

Asp.net File Upload Control Using with just one step

by munnaonc 27. May 2007 19:12

In our projects sometimes we need to use the file upload control. Asp.net 2.0 have
a build-in File-upload. In asp.net 1.x web controls didn’t had any builtin file-upload
control. Then we had to use a html input tag with type attribute set to “file” and
to use in server side add runat=”server” attribute.

<input id="myfileuploader" type="file" runat="server"/>

We all know how to work with a file upload control, today we will be discussion
about a new approach of file-upload. file-upload consists of two step . first we
have to select the file and then submit the page with a button or some kind of other
mechanism. To day we will try to minimize one step. If we want to upload the file
with just one step that is selecting the file here is the Technique

A file upload control which is eventually truned into a input html element have
three client side events

    * onBlur      
    * onChange
    * onFocus

we will utilize the onChange event… here is what we will do. frist add a asp.net
2.0 fileupload control in our page. then in pageload event add a attribute in attribute
collection. then write a javascript funtion to submit the form and in code do what
ever we whan….

 
task 1 : add a fileupload control

task 2: add the onchange attribute as FileUpload1.Attributes.Add("onchange", "doSomeStuff()");

task 3: add the javascript to submit the page

<script language="javascript"
type="text/javascript">

function doSomeStuff()
{

         document.forms[0].submit();

}

</script>

Thats it you are good to go.. in page load event check wheither the filename is
empty or not and then do the file upload.

VS 2005 Windows Work Flow ToolBox Section...

by munnaonc 11. April 2007 19:06

Hi Recently i had to work with Windows workflow foundation for some conceptual demo or proof of concept demo. During development time i faced a strange problem. some of the windows workflow tools are not showing in tool box.

 

BeforeReset

 

I try to reinstall the workflow extention for Vs2005 but the problem remain. if you see care fully i can not drag and drop a code activity from the tool box. That was a little but disturbing … then i reset the tool box. and every thing got back on line again. i just right click on the tool box a popup menu come up which has a reset menu item.

 

afterReset...

 

Some time in some other extention of vs this thing can happen. Dont forget to reset your tool window.

VS templates not working? Easy to get things back.

by munnaonc 6. March 2007 20:59

Recently I had to work with window SharePoint Service 3.0 and its development. I download the visual studio 2005 project templates for SharePoint development. I downloaded the project msi from Microsoft download site.

http://download.microsoft.com/download/e/8/a/e8aa8476-5af6-4f38-aed2-0247a99d2bc6/VSeWSS.msi

Installed in my local computer… but when I opened the IDE2005 project templates are not there…..

I got confused… and try reinstall the msi… but noting happed… I went to google and found few people is also suffering from this problem… the problem is my vs2005 is installed in different drive other that “c:\” and the installed temples are in default “c:\”… and then I moved my template in the drive where the IDE2005 is installed….

Location of the project templates is [your dive letter]:\Program Files\Microsoft Visual Studio 8\Common7\IDE…

There were two directories one if project template and other is item template… last thing that I did is to make ide identity the project templates….

For this I had to just a command in vs2005 comma prompt..

devenv /installvstemplates

I found help from the following forum… please go there for more detailed discussion…

http://geekswithblogs.net/ehammersley/archive/2005/11/08/59451.aspx

Hope this will help someone someday….

Asp.net Tree view control, very useful But.

by munnaonc 26. November 2006 20:30

Asp.net 2.0 ships with a whole new set of controls. Navigation controls are one of them. In navigation control we have three options

  1. Sitemap path
  2. Menu
  3. Tree View

TreeView

 

Recently I have worked in a project which is a demo project where I had the pleasure of using the asp.net 2.0 tree view control. Below I will be demonstrating a simple way to use the treeview and some things that we should know while we use tree view control of asp.net 2.0 in our projects.

 

Obviously tree view control has node property and nodes can be create dynamically and modify the node collection on runtime. But it’s for only level one node. For level two nodes node is created just the way it is, but need to add in the child node property. So in a sense tree view has node property and nodes have no recursive node property and to deal with child node, node has child node collection.

 

Constructor of Node class has several overloads. Actually 5 of them are there.

 

TreeNode tn = new TreeNode("Text");

TreeNode tn = new TreeNode("Text", _value);

 

Here we should always be careful about the value property. This value property must be distinct for each collection.

 

For example if we have a Tree Node consists of three Nodes and each and every done has value property as a same value. SelectedNodeChanged even returns always the first node of the collection.

 

TreeNode tn1 = new TreeNode("Node One",-1);

TreeNode tn2 = new TreeNode("Node Two",-1);

TreeNode tn3 = new TreeNode("Node Three",-1);

TreeView1.Nodes.Add(tn1);

TreeView1.Nodes.Add(tn2);

TreeView1.Nodes.Add(tn3);

 

In the web application if we select node three that is tn3 … in SelectedNodeChanged event we will have th1 as SelectedNode. I don’t know how this happened but surely it happened. But if we provide different value in the value field of the node constructor this was okay. Even if we don’t provide any value things work just fine.

 

Tree view has a wide range of configuration and style settings. Among these StaticItemStyle and StaticItemHoverStyle is most useful.

 

Well sometime we need to disable a node in our view. But TreeNode class do not have any enable or disable property, rather it has selection Action Property. We need to set the selection property value to none to make a node disabled.

Windows presentation foundtion.. visited

by munnaonc 31. August 2006 18:25
Recently we developed a spacer project. Goals for this project is to learn new technologies of Microsoft. Microsoft is developing the new generation of windows programming and web programming environment. As part of this evolution, Microsoft developing four major technology

1. Windows presentation foundation.
2. Windows Communication foundation.
3. Windows Work Flow Foundation
4. Windows Card Space

In our project we covered two technology that is WCF ( Communication Foundation ) and WPF (Presentation foundation). And we used recently released customer preview that is JULY CTP. In my point of view windows presentation foundation is a Break through in windows programming environment. Same interface is serving the UI for both web and windows. Pretty good. Event thought the performance is a good and big issue. I hope Microsoft is going to cover the lacks that WFP has in its Release product.

WCF ( Communication foundation ) this "the" future web service or inter-process communication service. or we can call the service of taking to every one. very well organized and well designed that can be used in local machine as windows service and also in web service.

More of .net frame work discussion will be listed in my blog.

But Buttom result is that i like the idea of both WPF and WCF.