Dailycode.info

Short solution for short problems

Int value to enum

Sometimes I post just very easy and simple things. This is one of them, but often I forget this and start looking for it on the web.

When you create an enum, its easy to extract the int value of the objects. But how can we find the corresponding object when we have the int value?

Enum MyEnum
{
Mark=0,
Jetro=1
}

Simple:

MyEnum enumValue = (MyEnum)0; //(this returns Mark)
MyEnum enumValue = (MyEnum)1; //(this returns Jetro)

You can cast an enum easely to int:

int intValue = (int) MyEnum.Mark;
 

Have a good day!


/3GB option in the Boot.ini (cannot open large files)

I installed WSS 3.0 on a windows 2003 server. Everything looked OK. I was thrilled to get the installation so easy and correct in the first try. But when I start using Sharepoint, I noticed that some files opened and other didn't. What was going on here? After digging for hours in the WSS administration, I couldn't find the problem. Then I started to google for a solution, but I can tell you, it was not easy. After testing a little while I noticed that files larger then 200Kb didn't open, smaller files did. So There was some kind of limitation on the server. I noticed that the files where correctly in the DB. So I concluded that it was not a Sharepoint problem. When I finally hit the correct search words in google I came up with this solution:

The Windows Server 2003 /3GB switch is not supported in Windows SharePoint Services 2.0 or in later versions or in SharePoint Portal Server 2003 SP2 or in later versions.

Look for more here: http://support.microsoft.com/kb/933560

So when I removed the /3GB part in the boot.ini file and rebooted the server, everything works fine. What a relief. I hope you didn't had to google as long as I did to find this solution!

//Added on 11/08/2008 by Mark Deraeve

I had the same error working woth word documents. But the error messages can be very misleading. Here are some examples of error messages:

or:

If you are having this kind of errors or even an error like: locked of checked out by ... and it doesn't make sense, then try firdt opening a small or empty document. If that works, you know it is this problem and you know the solution.

http://support.microsoft.com/kb/933560


Using webservices in a webpart

I'm developing webparts not on the server, but a simple develop machine. It is not possible to use the visual studio Web part extensions. So I create and copy the whole thing myself.

No big problems there. But then come the choice, adding the assembly to the GAC or not? I choose not to, because of security reasons. I just copy my DLL to the bin folder of the virtual directory. Works fine, I did had to put the web.config to medium trust and add this line to the web.config:

<SafeControl Assembly="SOP, Version=1.0.0.0, Culture=neutral, PublicKeyToken=93464d75f4108077" 
Namespace="MYNAMESPACE" TypeName="*" Safe="True" AllowRemoteDesigner="True" />
 

Don't forget to add the webpart, you can do this when you choose site settings and click on webparts.

When I started working with webservices in the webpart, it became a lillte more difficult. But thanks to google and some collegue programmers I solved this lovely exception:

System.Security.SecurityException: Request for the permission of type 'System.Net.WebPermission, 
System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
 

This site explains it good: http://store.bamboosolutions.com/kb/article.aspx?id=10405 

I extracted the steps you'll have to take in order to clear up this error:

You'll have to add these lines to the medium trust file (or a custom trust file): 

<IPermission class="System.Net.WebPermission, System, Version=2.0.0.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1"> 
<ConnectAccess>  
<URI uri="http://myserver:myport/mysitecollection\mywebservice.asmx"/
</ConnectAccess>
</IPermission>
 

The path of the trust files can be found in the web.config. In my case it was:

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\CONFIG
 

You can add multiple url's!


UpdateListItems

I'm developing a webpart that uses the WSS webservices to update en create list items.

Using the UpdateListItems method from the Lists webservice, it is possible to add or update listitems. I google a few minutes and came up with this solution:

try
{
	string sListName = "SOP response";
	string sSOPName = this.Page.Request.QueryString["qSOPName"];
	SOP.SPSLists.Lists list = new SOP.SPSLists.Lists();
	list.Url = "http://pmibeleudb02:777/SOP/_vti_bin/Lists.asmx";
	list.Credentials = System.Net.CredentialCache.DefaultCredentials;
	XmlDocument xmlDoc = new System.Xml.XmlDocument();
	System.Xml.XmlElement elBatch = xmlDoc.CreateElement("Batch");
	StringBuilder sb = new StringBuilder();
	sb.Append(@"<Method ID='1' Cmd='New'>");
	sb.Append(@"<Field Name='SOPName'>MarkSOP</Field>");
	sb.Append(@"<Field Name='Employee'>Mark</Field>");
	//sb.Append(@"<Field Name='Date' />");
	//sb.Append(@"<Field Name='EventDate' />");
	sb.Append(@"</Method>");
 
	elBatch.SetAttribute("OnError", "Continue");
	elBatch.SetAttribute("ListVersion", "1");
	elBatch.InnerXml = sb.ToString();
	XmlNode returnNod = list.UpdateListItems(sListName, elBatch);
 
}
catch (Exception er)
{
	_mylabel.Value = er.Message;
}
 

Then this error occured:

0x81020014One or more field types are not installed properly. Go to the list settings page to delete these fields.
 

This error was because I changed the Title field to SOPName, but the CAML name is still Title. If you have a simular problem but you can't find the caml name of the field, click to edit the field and look in the url at the end, there should be the CAML name of the field. When I used Title instead of SOPName it worked!

http://my server/SOP/_layouts/FldEdit.aspx?List=%7BB5343477%2D48A4%2D4C37%2D953A%2D153B7B2288E1%7D&Field=Title