Saturday, April 11, 2009

Task List Edit Assigned To field

When I tried to add task item on Sharepoint 2007 programatically I got an error mentioed that the field is maybe read only.

So....

You can not do :
item["Assigned To"] = "administrator";
item["Assigned To"] = "administrator@domain.com";
item["Assigned To"] = "domain\\administrator";


Instead, you have to specify the user ID from the user's list:

item["Assigned To"] = 1;

But how to tell what ID does a user have?
The only way I know of is using the "Users" property of the SPWeb object.
Lets say you want to assign the field to "ahmad@domain.com" (you only know the email).

you can use the following code:

item["Assigned To"] = item.ParentList.ParentWeb.Users.GetByEmail("ahmad@domain.com").ID;

Sunday, April 5, 2009

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

Problem: when I try to read xml file on the server through custom webpart on the portal ,it give below error.

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

Cause: The default trust level on our test site is set to wss_minimal which does not grant us permissions to use the SharePoint Object Model from the code.

To solve this error :

There are three different ways to get over this permission problem: we can add our assembly to the GAC to run under full trust, change our web.config and set the trust level to Full, or create a custom trust level by modifying wss_minimaltrust.config with just enough trust to get our code working.
Web Part Deployment Options, the third option is the recommended approach we will take to resolve our problem.

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

Saturday, April 4, 2009

Create view that shows all Lists (With the same type) in the site collection

  1. Create your new Contenet type the have List type "item" name it "MyCustomContentType"
  2. create custom List Nameit "MyCustomList".
  3. Go to List setting and allow mange content type.
  4. Change the content type of "MyCustomList" to "MyCustomContentType".
  5. Save List as template.
  6. Open a Windows SharePoint Service v3 Team Site in SharePoint Designer.
  7. Insert a view on a the Announcements list with the Title, Body, and Modified fields.
  8. At the top of the Data Source Details task pane, click “MyCustomList” to open the data source properties for the current view.
  9. Click on Fields and remove all fields except ID, Title, Modified, and any of your custom link.
  10. Switch to code view, and search for DataSourceMode
  11. Change the value from List to CrossList
  12. Next search for selectcommand
  13. In the select command, type immediately after the opening quote, and leave the rest of the selectcommand as it. You should see something like this: selectcommand="<webs scope="'Recursive'"></webs><View> ...”
  14. Save the page and browse to it (F12).