Today I came across a requirement of showing an swf file in the webpart. So I thought I will upload the swf file in folder and give its url to the webpart. But then that will be hardcoded path. What will happen if the user deleted that folder or rather deleted that file itself? So my webpart will not run.
So I found some alternative to this and thought of embedding my swf file and js file in webpart itself. I googled on how can I do this, and here are the steps for embedding the files in the webpart itself.
I ll assume that you are ready with the Webpart and you just need to remove the hard coded file’s url’s in your webpart. And i ll be using swfobject.js file in this example you can change the file and the type though, as per your requirements.
- Add swfobject.js file in the same project as webpart.
- Right click on js file select properties and change build action to “Embedded Resource”.
- Make an entry in AssemblyInfo.cs or AssemblyInfo.vb file like
[assembly: WebResource("ReadENote.swfobject.js", "text/js")]
format : [assembly: WebResource("<project namespace>.<filename>.<extension>", "<content type>")]
Note : Make sure you specify the namespace along with filename else it will not recognize the file.
- You can access this embedded resource in your webpart code like this
Type t = typeof(<webpartname>); //e.g. Type t = typeof(ReadENote);
string js = “<namespace>.<filename>.<extension>”; //e.g. string js = “ReadENote.swfobject.js”;
jslocation = Page.ClientScript.GetWebResourceUrl(t, js);
Page.ClientScript.RegisterClientScriptResource(t, js);
This code will embed the specified file, in this case swfobject.js file in my webpart.
Note: you only need to use the last line “Page.ClientScript.RegisterClientScriptResource(t, js);” if you are using the javascript file. If you are using some other file like an image file or swf file, you can use the jslocation in place of your hard coded location.
- my previous code to embed swf file looks like this
strBody = strBody + “var so = new SWFObject(\”notes.swf\”, \”stickies\”, \”250\”, \”250\”, \”9\”, \”#FF6600\”);”;
- my code after using these steps will look like this
Type t = typeof(<webpartname>);
string js = “<namespace>.<filename>.<extension>”;
jslocation = Page.ClientScript.GetWebResourceUrl(t, js);
strBody = strBody + “var so = new SWFObject(\”" + swflocation + “\”, \”stickies\”, \”250\”, \”250\”, \”9\”, \”#FF6600\”);”;
Make these changes, build and deploy your web part.
Enjoy dynamic coding and prevent hard code.
We have something called as Fun Friday’s in our office we normally celebrate that every alternate friday. What we do in that is play games and enjoy. All it does is it keeps you fresh and agile its one of the most happening thing in my office. And the games are based on the theme or some festival which is goin on or which is awaited. The winning team is presented with choclates.
This friday it was Friendship day which was comming up this sunday. So we decided so have something related to friendship some game related to friendship but our different ideas were all used in the previous fun friday’s so we had to think about some good idea for this Fun Friday to celebrate Friendship’s day.
So we came up with the idea of Face Painting. We had created 5-6 teams of 7-8 members each of these 7-8 members 2 members were to be face painted and other need to paint their face and the theme was Friendship. So my team thought of painting the Tom and Jerry as they are very good friends because they cant live together and best part of their friendship is they cant even live without each other how much ever they fight but they cant live with and without each other. Here are the pics from this time fun friday,
I just went through one of the video which showed how can you enhance intellisence feature in Visual Studio for the user-defined things.
Let me explain this to you in detail, suppose you have a class containing few functions and properties, When you create an object for that class and access its function all you can see in the intellisence is the name of the function without the description, but when you look at the inbuilt function in any of the inbuilt class you can see the description of that function.
Have you ever thought why so?
This is just because they have commented their code. You can also have your function showing the description of what it does in the intellisence and even pass the description for the parameters. All you have to do is provide a proper comment for your code. That is what a good programmer does. Here is the sample of the comment you must provide,
Here you can see the summary which appears as the description and the parameter list which will show the description for the parameters too. So keep practicing this to be a good programmer although there are various things which you should practice but this is one of them.