The type ‘System.IO.Packaging.Package’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘WindowsBase’


While I was working with the Open Office XML SDK 2.0, after I added the reference to the DocumentFormat.OpenXml assembly and tried to build the application I ran into this error message.

The type ‘System.IO.Packaging.Package’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’

Turns out, all you need to do to fix it is to just add another reference to WindowsBase assembly that is found in the .NET Tab.

Unknown server tag ‘asp:ScriptManager’ After having AjaxControlToolkit.dll referenced


Yesterday I was working on a project which had the AJAX Extensions in use. It’s primarily a .NET 2.0 application and I had .NET Framework 3.5 SP 1 installed on my system. It was working normally and all of a sudden I got this error that: Unknown server tag ‘asp:ScriptManager’

It was strange because every thing was working and I had the reference to the AjaxControlToolkit.dll.

I found out that by adding the section below to the <system.web> node in the web.config solves the problem:-
<pages>

<controls>

<add tagPrefix=”asp” namespace=”System.Web.UI” assembly=”System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35″ />

</controls>

</pages>

How to detect a mobile browser in ASP.NET


I’ve been having this issue with mobile development for quite sometime that I couldn’t get the mobile browser accurately by just using the Request.Browser.isMobileDevice property and I’ve found this piece of code here

Looks pretty useful.


public static bool isMobileBrowser()
{
//GETS THE CURRENT USER CONTEXT
HttpContext context = HttpContext.Current;

//FIRST TRY BUILT IN ASP.NT CHECK
if (context.Request.Browser.IsMobileDevice)
{
return true;
}
//THEN TRY CHECKING FOR THE HTTP_X_WAP_PROFILE HEADER
if (context.Request.ServerVariables[“HTTP_X_WAP_PROFILE”] != null)
{
return true;
}
//THEN TRY CHECKING THAT HTTP_ACCEPT EXISTS AND CONTAINS WAP
if (context.Request.ServerVariables[“HTTP_ACCEPT”] != null &&
context.Request.ServerVariables[“HTTP_ACCEPT”].ToLower().Contains(“wap”))
{
return true;
}
//AND FINALLY CHECK THE HTTP_USER_AGENT
//HEADER VARIABLE FOR ANY ONE OF THE FOLLOWING
if (context.Request.ServerVariables[“HTTP_USER_AGENT”] != null)
{
//Create a list of all mobile types
string[] mobiles =
new[]
{
“midp”, “j2me”, “avant”, “docomo”,
“novarra”, “palmos”, “palmsource”,
“240×320”, “opwv”, “chtml”,
“pda”, “windows ce”, “mmp/”,
“blackberry”, “mib/”, “symbian”,
“wireless”, “nokia”, “hand”, “mobi”,
“phone”, “cdm”, “up.b”, “audio”,
“SIE-“, “SEC-“, “samsung”, “HTC”,
“mot-“, “mitsu”, “sagem”, “sony”
, “alcatel”, “lg”, “eric”, “vx”,
“NEC”, “philips”, “mmm”, “xx”,
“panasonic”, “sharp”, “wap”, “sch”,
“rover”, “pocket”, “benq”, “java”,
“pt”, “pg”, “vox”, “amoi”,
“bird”, “compal”, “kg”, “voda”,
“sany”, “kdd”, “dbt”, “sendo”,
“sgh”, “gradi”, “jb”, “dddi”,
“moto”, “iphone”
};

//Loop through each item in the list created above
//and check if the header contains that text
foreach (string s in mobiles)
{
if (context.Request.ServerVariables[“HTTP_USER_AGENT”].
ToLower().Contains(s.ToLower()))
{
return true;
}
}
}

return false;
}

How to use an OR in a query in EntitySpaces?


It’s simple, yet not very obvious. All you have to do is to change the normal behavior of the commas you use in the Where function to act as an OR. You’d do it like this:-

ObjES.Query.es.DefaultConjunction = esConjunction.Or;
ObjES.Query.Where(<<Go ahead with using the commas that usually defaults to an AND conjunction>>);

oh and I almost forgot to mention my colleague Bilal mentioned this to me. So special thanks to him as well.

How to remove ReadOnly Attribute from a file?


Hello friends,

Here’s a nice little piece of code you can use to change file attributes of a particular file, its particularly useful when you’re trying to delete a read only file.

string savedCardFilePath = “My absolute file path”;

if (File.Exists(savedCardFilePath))
{
/*
* Remove readonly attribute off of the file if it exists before execution
*
**/
if(File.GetAttributes(savedCardFilePath) == FileAttributes.ReadOnly)
File.SetAttributes(savedCardFilePath, FileAttributes.Normal);
File.Delete(savedCardFilePath);
}

 

UPDATE May 14, 2012:

There have been some problems reported and better solutions given on this article so I updated the code to:

FileAttributes attributes = File.GetAttributes(file);

if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
File.SetAttributes(file, attributes ^ FileAttributes.ReadOnly);

Thanks for the feedback and sorry about the mistake 🙂

 

 

How to use OrderBy() for multiple columns in EntitySpaces?


You can pass multiple columns in like this:-

collection.Query.OrderBy(collection.Query.ProductID.Descending, collection.Query.CategoryID.Ascending)

How to manipulate Session in Http Handlers


There is a common issue that you can’t manipulate session objects in http handlers, the files with ASHX extension 🙂 Well normally you can read the contents in the session via context.Session but you can add/remove/modify that in there. So how do you do this:

The answer is simple: Just implement the IRequiresSessionState interface. It doesnt have any method to implement so you dont have to worry about any details, this just notifies the runtime that Session can be manipulated in this context. So your class declaration would look something like this:-

public class SetLabels : IHttpHandler, IRequiresSessionState
{

A Nice Javascript Calendar Control for your applications


Javascript Calendar/DateTime Picker control
Javascript Calendar/DateTime Picker control

I got this nice little gadget from a friend of  mine who also didnt know where it originally came from. This one’s made by Nick Baicoianu in 2006 and distributed under the GNU license. It had problems with Firefox 3 where it wasn’t showing anything in the dropdown for the years. Upon closer inspection I found out that it was using the getYear() function which was returning 3 digit values for years in Firefox 3 — So you had to either detect it first and add 1900 to it but this wasnt a very good looking solution to me so I started looking for other options and I came up with the getFullYear() function. It returns the proper 4 digit year notation in all browsers. So now its compatible with IE 7, FF2, FF3, Chrome, Opera and Safari as well.

Its a handy little gadget to have in your arsenal. I like it very much. Hope you’ll like it as well.

P.S: The download contains the include folder which has the js and css files for the calendar.

Download the Code

How to use TinyMCE in ASP .NET?


howdy everyone,

well, its been quite a few days since I dropped something on my blog, been eXtreeemly busy these days. Did any one missed me?? 😀

OK, today I got this little test application for you people who are wondering: “how to use TinyMCE in ASP .NET?”. Trust me, its very simple and very straight forward.

Here’s how I used TinyMCE in my application:-

I just added this in the head tag.

<script language=”javascript” type=”text/javascript” src=”tinymce/jscripts/tiny_mce/tiny_mce.js”></script>
<script language=”javascript” type=”text/javascript”>
tinyMCE.init({
mode : “textareas”,
theme : “simple”
});
//you can also used “advanced” for themes
</script>

After that just put a multiline textbox in and it will take the form of a feature rich WYSIWYG editor.

You can also ‘skin’ this as well. By default the download comes with two skins, one is the advanced and the other a much simpler one.

Download the code

How to get the file name from a full file path?


If you have a full file path like D:\My Documents\myimg.jpg and you want to get just the file name myimg.jpg, you can get it with the help of the Path class in this fashion:-

In C#

string filename = Path.GetFileName(“D:\My Documents\myimg.jpg“);
In VB .NET

Dim fileName as String = Path.GetFIleName(“D:\My Documents\myimg.jpg”)