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
{