Jul 27

Hi,

Today I encountered an error in which I was having problem of showing contents of <div> tag on the top of a flash movie. I am using div tags as menu to show the menu on hover events. It was working fine till I get a flash movie beneath the menu. In case of flash movie my menu started to disappear behind the flash movie. After doing lil search on google I found the solution which is given below:

You just need to provide the following parameter to the object tag which is displaying the flash movie.

<param name="wmode"value="transparent"/>

I have found this solution after some googling. Here is the link from where I got this solution.

http://www.ravinderweb.com/page/Working-with-Div-and-Flash-Movie.aspx

So follow the above link if you are interested in complete description.

Regards,

Shahid



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags:

May 25

Filewatcher

C# | General | Tips and Tricks 119 Comments »

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
 

Working with FileSystemWatcher Class

  

Hey, if you are here to find the answer of this question "how to make sure in Created event of the Filewatcher that the file which is just created is completely copied?" then you are at the right place..

FileSystemWatcher class listens to the file system change notification and raises events when a directory, or file in a directory, changes.. In this article I’ll discuss

fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)  event of FileSystemWatcher class. Working with this event is easy. You just need to capture this event and then write your code in it. BUT there is a problem in this event which is that the Created event is fired immediately as soon as the path of the file is created in the observing directory. This can be clearly explained with the help of a following scenario: I want to observe a Directory say C:\\Test. I wrote a window service which uses the FileSystemWatcher class to observe that directory. I want to pass any new file which is created in this directory to another method which processes this file. Suppose my file’s size is large (e.g. 500mb). In my window service the Created event of the FileSystemWatcher is triggered as soon as the file’s path is created in the directory, but file is not copied completely in the directory. How to solve this issue? .Net does not provide any method or event which can tell me that the file is written completely.  I tried to solve this problem and though I achieved my task, but this is not a good solution.  In the Created event I made a thread. So for each new file a new thread will be created, so we can serve each new file without any delay. In that particular thread, I tried to open the file. If file is opened successfully, then it means that file is copied completely and is available for processing. If not, then try to open the file again. Repeat this process until the file is available. Here is the code: 

void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)

{   

       Thread _MyThread = new Thread(new ParameterizedThreadStart(this.PerformActualTask));    

       object[] Parameters = new object[] {e. FullPath };    

       _MyThread.Start(Parameters);

 

private void PerformActualTask(object parameters)

  

 //The parameter for this thread body   

 object[] Parameters = (object[])parameters;  

//Full path of the newly created file  

string _SourceFile = (string)Parameters[0];  

int WaitBeforeGiveUp = 300;  

while (true  

     

 try     

        

  //Try to open the file        

  FileStream fs = File.Open(_SourceFile, FileMode.Open);       

  {         

   //We are here because file is successfully opened         

   fs.Close();      

   //Now perform operation on that file      

   }    

 }    

 catch (Exception ex)   

       

  //If exception occured then decriment the wait before give up and ask the thread to sleep       

  if (--WaitBeforeGiveUp > 0)       

        

    // file is not available yet      

  }     

 else     

         

   //if waiting time expired.         

   // SHOW GIVE UP MESSAGE     

 }      //cause the thread to sleep     

 Thread.Sleep(1000);   

} 

}

  

In the code I made some changes which are that I tried to open a file for a particular period of time. If file opened in that period then kool, else I stored a msg in the event viewer that I have given up.     



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags:

May 04
 

Remove command bar from Add-ins in MS Word

 

Some time we need to develop some add-ins to fulfill our requirements in different software (e.g. MS Word). Few days back I was developing an Add-ins for MS word. The requirement was to add a button in a command bar of the MS-Word. I successfully added button in the command bar and also wrote code against the event handler of that button. But unfortunately whenever I ran the MS word, my code started to add the same button in command bar again and again. To overcome this problem I wrote code which forcefully removed that custom button from the command bar on the closing of the ms word.

The code which was removing that button on the closing of the word was in the Application_DocumentBeforeClose event of Add-in. But that code didn’t give me the expected output.

There was nothing wrong in the code, because I debugged the code and in the shutdown event I made sure that the command button exists in the command bar. If it exists then delete the button. But again that code didn’t work. And interesting thing was that the code segment which was checking that the command button exists in the command bar always gave me true and in the true section I was deleting that button, but I don’t know that why it didn’t work. I was deleting the command button by using the ID of the button something like this:

1.     Office.CommandBarPopup foundMenu = (Office.CommandBarPopup)

2.     this.Application.CommandBars.ActiveMenuBar.FindControl(Office.

3.     MsoControlType.msoControlPopup, System.Type.Missing, IDOfControl, true, true );

4.     if (foundMenu != null)

5.     {

6.       foundMenu.Delete(false);

7.     }

The above code didn’t work L 

In line 3, I used the IDOfControl to find the command bar button, but it didn’t find that control. Though I tried to use the Id.delete() method, but it also didn’t work for me. Then I changed the Line number 3 and instead of using the ID of the control to find the command bar button, I used the tag of that control and this change in code successfully find the control and this change also make the Line 6 to give the expected output.  So if you are also facing this kind of situation then try to use the tag of the button instead of its ID. I am sure it will work. Well I was developing the add-in for office 2007. This code will probably work in other version of MS word too. The reason that this code work is given below: 

Add-in Express identifies all its controls (commandbar controls) through the use of the ControlTag property (the Tag property of the CommandBarControl interface). The value of this property is generated automatically and you don’t need to change it. For your own needs, use the Tag property instead.       



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags:

May 01

iframe source on the fly

ASP.Net | C# | Tips and Tricks 50 Comments »

Currently rated 5.0 by 2 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

This article will explain that how to load pages dynamically in IFrame from the code behind.

Actually few days back I encountered a situation where I was interested to set the src of IFrame dynamically. Some of the solutoin which I found on the internet were some thing like this:

 Declare a Generic control:
protected System.Web.UI.HtmlControls.HtmlGenericControl IFrame1;

Then, you need to do findcontrol to identify the control on the page and
typecast it:

HtmlControl IFrame1 = (HtmlControl)this.FindControl("IFrame1");

Now you can access the src property:

IFrame1.Attributes["src"] = http://www.live.com ;

I tried this solution but it did not work. Cry

SimilarlyI found many other solution saying exactly the same thing which I mentioned above. I posted on different forums and the answer was that this solution might not work if you are using master pages. And they gave me another suggestion that instead of passing IFrame1 (i.e. the ID of your Iframe) just pass the client ID of the IFrame to Findcontrol. But that solution also did not work for me.

Then I came across a POST which stated that turn your HTML snippet into server side code and then use the above code i.e. (HtmlControl IFrame1 = (HtmlControl)this.FindControl("IFrame1");)

I did not try this suggestion, instead I only turned my IFrame into a server side control by adding a runat="server" attribute into my IFrame and then like any other server control I accessed my IFrame from the code behindLaughing

I hope that this will help all who are facing same kind of problem.

Here is the summary:

  • Turn your IFrame into a server side control by adding a runat="server" attribute, like this:
<IFrame id="myDynamicFrame" scrolling="auto" runat="server"/>
  • Now you can access this control from your code behind file and you can set its src property on the fly, like this:
myDynamicFrame.Attributes["src"] = "http://www.shahidriaz.com";
 


[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags:

Mar 07

Some interview questions

ASP.Net | General | Tips and Tricks | Visual Studio 121 Comments »

Currently rated 3.0 by 5 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Today I was surfing on the blog of Sheikh Ahmad and I saw some interview questions related to .Net. I will try to give answers of some of the questions.

Here is a question from his blog:

How can we get the variables of first form from second form without using query string and session etc?

Answer:

In these kinds of questions the interviewrs are actually try to detrmine that how much do you know about the .Net 2.0. It is very simple to get any control of the Page by using the this keyword or just from the ID of the control like

lbltest.Text = "hello";

But now the critical part of the question is that how to get the variables of first form from second form without using query string or session etc. This question itself suggests that we can access variable of one form from another using the query string or session etc but the interviewers has asked you not to use this approach.

What if I ecounter this problem in my work life? To solve this I will try to use an approach in which I can get the instance of the first page in the second page. Now the problem is that how to pass the instance of the first page in the second page without using query string or session etc. The answer is Cross Page posting which is a new feature of .Net 2.0. By default Controls like button , image button of ASP.Net post back to same page. If you want to post back to some other page instead of the current page then you can set the postbackUrl of these controls (i.e. Buttons,LinkButton,Image buttons). This is called the Cross Page posting and it is the feature of the .net 2.0. By using this appraoch you can navigate to the second page and in that second page you can access the first page too.

Suppose you have two pages page1.aspx and page2.aspx. In page1.aspx you have a button and a lable. Set the PostbackUrl of the button to page2.aspx and in the page2.aspx use previouse page property to get the previouse page's instance like this:

Page source = this.PreviousePage.

By using this approach you able to get the instance of the first page in the second page without using the Session or Query string. Now you can use this instance to get the variables, View state etc of the first page. 

 

Question: What are collections and why we use them?

Answer: Simply speaking Collection is a container which is used to hold the objects.

The second part of the question is that why we use them?

Well in programming we write differnt kinds of classes then we declare the objects of those classes. Those objects perform differnt functions and communicate with each other too and after performing their action they give output to some other kind of objects. So we use the container or collection to hold these objects. 

The question arise that what is the need of this container in the presense of the array? The answer is that array can not be used to hold differnt kinds of objects. Secondly we need to set the length of the array when we declare it but this is not the case with collection. The size of collection is dynamic. You just need to declare the collection and that is it. In collection you do not need to know that how many and what types of objects you are going to hold in collection.

Like other programming language C# has differnt kinds of container or collections i.e.

  • Stack
  • Queues
  • Hashtable
  • ArrayList 

Actually what ever you add in a collection becomes an object. It is said that every thing in .Net is an object, so what ever you add in a collection becomes object thus loosing its identity because in collection they are now in the form of object. The conversion of types into object is done by the .Net itself and it is called the Boxing. And this conversion of types to object is also called upcasting and it is always safe. Why it is always safe? Because you are converting the types into their super class (i.e. object of your class into System.Object) and we know that every thing in .net is derived from Object so this conversion will be safe always. Now when we get back our data from the collection it will be in the form of Object instead of the form in which we have added it in the collection. So when we get the data back from the collection then we have to cast it back into its orignal type. The conversion of the object into some specific type is called unboxing. Unboxing is also called downcasting. Downcasting should be done carefully because if you try to cast it into some wrong type then you will get the error. e.g. Casting the Circle into rectangle is wrong. So downcasting should be done carefully. Upcasting is done by the .Net itself and can be done programmatically but it is not dangeriouse while downcasting could be dangerious if not done properly.

That can be explained like "Circle and rectangle are always shape but it is not necessary that Shape is always a circle or rectangle"

Question: Shellow Copy vs Deep Copy?

I already wrote an article that how to impliment Shallow copy in .Net. Here is the Link of that article. It might help you.

http://www.shahidriaz.com/post/2008/12/07/ShallowCopy.aspx

 



[KickIt] [Dzone] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Tags: ,