Tuesday, December 20, 2011

Synchronous between 2 site collections to make a backup data

There was many ways to create a backup for your site collection from content-database. For the others purpose, you will find out the best solutions for you situation, and in this sort topic, I will show you how to create a backup content of site collection in disaster case or crashing data.

Content Deployment Path is a part of tool using in SharePoint Server 2010 to sync data from source site collection to destination collection. Source and destination site don't need to be in the same farm server, they may work on other farm but between 2 farms must have a connection. That means you have to have an account can access to destination site collection.

There are a lot of jobs created and sometime it make your system to be slow down or not responding, however it actually only happens for the very first time running.



One more thing need to be warned, that is, if you are performing on crossing server farm, you should take a time to manage security between the farms because SharePoint requires transfering data by secure socket network, if so, you must go to the Central Administration to reconfig Content Deployment Settings to do:
- Enable listening between the sever farms by setting Accept incoming content deployment jobs
- Select Do not require encryption option if you didn't work on SSL administration

After create an Content Deployment Path, you will see the item in the list, and create a job to perform action.



Conclusion: you can monitor the deployment jobs in Central Administration section, and manage all jobs in the setting page. Note: please don't set the schedule too short to avoid the conflict data between 2 jobs in the same path.

Friday, December 16, 2011

Series solutions on document management for officer - Part 3

At the previous posted, I recommended 2 solutions for officer employees. SharePoint 2010 OOTB has not supported enough components to work on documents especially about document management and collaboration. Security is also an important thing and could not separate from content management actions. If there are many actions on the same document at the same time, it would be conflicted when user perform saving execution. Collaboration is the best solutions to solve this problem and for now Microsoft had released a lot of components for collaboration such as Office Web, SharePoint Online (Office 365),... However, another scenarios often has been used frequently in office that is to share some documents (items) in the same department or another departments.



This topic will reduce (save ) your time when you work on document/content management. I produce this component to help you share (items) your documents, it allows:
- Share item(s) to one or many people with specific permission, the permission list is taken from SharePoint permission level.
- Privately item(s) from another users, except for System Account and Site Collection Admin.
- Inherit from parent.

Limitation for free this component:
- Cannot share item(s) for many people with many permissions. For example, if you need to add some people /groups with FullControl and Contributor for this item.
- Cannot get the permission editing for item which are the same permission items.
- Only support SharePoint 2010

Download here

Tuesday, November 29, 2011

Series solutions on document management for officer - Part 2

In the previous post, I just reserved a piece of package of document management for officer. In the daily tasks, I think it's very useful if there is any robot functioning to perform our tasks. It's like a command in SQL and executes many times, sometime it makes us feel uncomfortable or tired with a boring jobs. That's why I think it's really useful for office, especially some people work in Acc Dept and HR Dept.

In this topic, I introduce a new feature in a series of small tool for officer. That's download a multiple files from document library or picture library.

SharePoint OOTB has supported already a feature named Download a copy in Copies category of Ribbon. However, to get a copy of file, user can perform by right-click on the file name and select Save file as from context menu of Internet Explorer. Of course with SharePoint, user has a lot of methods to download a copy of file, but the question is how to get many files and folder into a package? There is only way to do that is to go through every item and download, then using compressed function has supported by windows to zip all in one.



There are some limitation of free version:
- Not supported compressing all sub-folders.
- Not supported other zip type, just using "zip".

There are features of this tool:
- Allow compressing files and folders in the same level.
- Supported for SharePoint Foundation and Office Server.

It's available to download here.
(... to be continued )

Thursday, November 24, 2011

Series solutions on document management for officer - Part 1

SharePoint is a portal with the strength functionalities for collaboration and content management. There are a lot of new features to improve the activities of user and support the useful tools for almost kind of user who are using SharePoint 2010. That's perfect! However, Microsoft is always only build a framework and background technology for all their product and their partners will build a product as component or build a solutions to help IT Pros or IT Manager build up a service for their business. So, there are many companies only support the solutions or consult the customer by SharePoint administration expert. I've also consulted for some companies and build the solutions for a part of or whole their departments. The best things I have after finish every contract is how to fullfill the requirment while SharePoint features are not enough to reach all situations.

Luckyly, I am a developer. This is the only one advantage and I have to think about it. if I have a budget I just only buy some widgets or components from 3rd party and select the best product to match the requirements. I think this is not difficult but the most imprtant thing is how to mantain the product id there is many many products from another company and developer like me can not handle! In this series, I will show all you guys see some my opinions to solve a little taks but it's actually useful for IT managers, especially end-users.

This is a first topic to talk about requires' Officer, that is how to move a lot of document to another site. The limitation for free here are:

- Not support move multiple items, that mean these documents (files) still are in original list. They are not deleted after copy to new location.
- Not support overwrite method. If this feature is enable, the file is copied to the destination list will not overwrite instead of adding subfix "-(copy)"
- Not support copy the folders, it's avaible upon request.
- Not support cross-site, that means moving these files to another server farm.
- Not support sending to multiple sites

Here are the list of features in free version:
- Copy multilple items to onother location.
- All file types are supported.
- Support for both Foundation and Office Server
- Not need to install or activate Document Set feature.



Note: at the destination URL, please enter the short path, not including SitePage/Default.aspx or default.aspx

Trial version is available here. Download here. Hope this help.

Wednesday, November 23, 2011

How to get distinct value from splistitemcollection

In many cases, we need to get the distinct data like SQL or even only get the separately data. it will be complicated if we are working on SharePoint 2010 because of performance. There are at least 2 scenarios we have:

  • Max throttling 
  • Performance with large list
Now, i also have a small code to get the data for distinct:


SPListItemCollection collection = list.Items;
DataView view = new DataView(collection.GetDataTable());
DataTable result = view.ToTable(true, "[Column Name"]);


By using DataView and DataTable we can get the distinct value from list, but if it's a large list you only get Max Throtting items in a collection, others will be missing. The most important thing is this way is easy to use.

IEnumerable enumerable = list.Items.Cast<SPListItem>().Select(itm => itm["Column Name"]).Distinct();

Or you can use Linq to select the distinct value, this way will not be recommend because of performance but it will return exactly data if the maximum return records were not exceeded the Max Throttling.

It's up to you to choose any way, but hope this help.

Sunday, November 20, 2011

SharePoint and SQL intergrations event

We've announced our next exclusive live chat on Facebook! Join Jesse Shiah, CEO of AgilePoint, and Gideon Bibliowicz, Senior Product Manager - Enterprise Lead for Microsoft SharePoint of Microsoft SharePoint, on December 1st at 11am to ask them questions about SharePoint and SQL integration. Any technical questions you have are fair game. Don't miss your chance to go right to the experts and learn how SharePoint and SQL benefits businesses of any size. RSVP on the event page:

http://www.facebook.com/events/179333768823652/

Sunday, November 13, 2011

Format DateTime in SharePoint 2010 based on XSLT 1.0

If you were bored with the date time formatted showed in the list by SharePoint and you think it should be changed to how it's easy to view it. The difficulties come from a lot of problems especially XSLT in SharePoint 2010, it was never upgraded from SharePoint 2002, still using version 1.0 until now. That's the bad thing I had when I was working on SharePoint.

Of course, there are many options for you developing on SharePoint product, I mean you can use ContentQuery Web Part to correct the date time format like FaceBook or Google Plus:

However, to do that, now you just follow up this instruction to customize your xslt and see how it shows on the page.

Click here to download the library.

1) Copy the content of file after downloaded, paste it into the file named "thread.xsl" in folder 14/Template/Layouts/Xsl

2) Go to the line for template called "StatusBar" (<xsl:template name="StatusBar">) and remove all the code for Modified date time. Or replace by:

<xsl:call-template name="Bamboo_FormatDateTime">
    <xsl:with-param name="theDate" select="$thisNode/@Modified."/>
    <xsl:with-param name="theDateFormat" select="$thisNode/@Modified"/>
</xsl:call-template>

3) Save and reset IIS

Note: 
- You can put the code anywhere if you want to show the time stamp more friendly.
- Just StatusBar column has defined "Modified." field in the schema, it's original value of Modified column. So, if you do not find out the value of "Modified." that means, in the schema file, the field did not create a reference to original value Modified.
- You also don't care about the LCID of site or user locate, because the value of "Modified." always return the value in 1033 regional and the format function based on this column to show friendly.

Unlock uploading file in SharePoint 2010

By default, SharePoint locked the uploading file with some extensions, these extensions may cause the damage your server and user will take advantage of uploading to send a script, virus and even the code executable and control your server from remoting. So, SharePoint has been locked by default to be sure your server to be protected safety.

You will get an error if you try to upload the file with restrictive high level:


However, in some case, you need to unlock to upload the file for internal process, or only in local. It's very simple by remove the extension out the locked list.


Go to Central Administration -> Web Application, on the Ribbon click on Blocked File Types, the remove the extension necessary. This is only effected on each Web Application. To be more safely, put it back the blocked list after finished the uploading, only open if it is really necessary.

Monday, October 24, 2011

Share a SharePoint Blog Post/Discussion Board to many Social Networking

Once the discussion board and blog has been published on the internet, the Administrator wish always sharing the interesting thing to everyone through Social Networking such as Facebook, Twitter,... There are many people  know your site if the post was shared to many ways, many sites...

Look at the picture:

Step by step:

1) Regist an account on http://sharethis.com

2) Login by this account, create an Get a button, then customize the number of networking, size, template,...

3) Get a code.

4) Open file thread.xsl in 14/Hive location LAYOUTS/XSL folder. Point to line at: 650 and paste this code:

<xsl:if test="(@BaseViewID='1' or @BaseViewID='2')">
// THE CODE FROM sharethis.com
</xsl:if>

THE CODE FROM sharethis.com as picture below:



5) Save and reset IIS.

Thursday, October 20, 2011

Fix Blog Comment bug for SharePoint 2010

SharePoint Bug:

Scenarios: Turn on anonymous access to the comment list with full functioning such as Delete/Add/Edit and View item.

Work As Design and Problem: If you logged into site by Anonymous,  of course, you can post the comment, edit and delete the comment. However, these comments which has created by Anonymous, all anonymous can view these comments although they are not approved. Especially, anonymous can be edit/delete the comment which posted by another anonymous. And then, if you logged into by authenticated account, you will not see these comment because they are not approved yet. That's so funny.

Resolve: If user log-in the site by anonymous and post the comment, item needs to be approved before showing on the page. So, after user click post comment button, they will see nothing change on the page. It's a little confuse but it should be.

More thing, although edit permission is turned on for anonymous but it should not be use in this scenarios, because no one knows who is edited and editing/deleting to be complicated. So, we must check if anonymous access and the comment has been approved, just show as normal.


Just change a little thing. Go go 14/hive and open folder Layouts/xsl, open the file blog.xsl and go to line at 418, insert the line:

<xsl:if test="($Userid &lt; 0 and $thisNode/@_ModerationStatus = 'Approved') or ($Userid &gt; 0)">
//SharePoint Code

and insert the line at 448 a close tag

</xsl:if>

See attach:

Warning: if follow this instruction, the WAD of SharePoint default will not keep correctly, this is also new view for end user and I think it should be change like this and make sense for all cases.

Friday, October 14, 2011

Access denied for Anonymous users with custom xslt

SharePoint Bug

Sometime I had a stress with SharePoint customization, especially on XSLT data transform.
My scenarios is:
- Create a custom view for any list.
- Customize XSLT to render UI for my stituation.
My Problem is:
- With authenticated users, it works fine and smoothly
- Got a notice: Access denied. You do not have permission to perform this action or access this resource for Anonymous users.



I am a "SharePointism", so the first thing I looked into the SharePoint log file. it's very lucky, I got the message: "Error while executing web part: System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))     at Microsoft.SharePoint.Library.SPRequest.UpdateWebPartCache(String bstrWebUrl, Boolean bAllUsers, String bstrID, Byte[]& ppsaData, Boolean fOMCall)     at Microsoft.SharePoint.WebPartPages.SPWebPartManager.CacheWriteInternal(Guid storageKey, Byte[] cacheData, Storage storage, Boolean omCall)     at Microsoft.SharePoint.WebPartPages.BaseXsltListWebPart.get_CustomizedXsl()     at Microsoft.SharePoint.WebPartPages.BaseXsltListWebPart.LoadXslCompiledTransform(WSSXmlUrlResolver someXmlResolver)     at Microsoft.SharePoint.WebPartPages.DataFormWebPart.GetXslCompiledTransform()     at Microsoft.SharePoint.WebPartPages.DataFormWebPart.PrepareAndPerformTra..."

Just guess that because I turned on the "Data Web Part Caching" and it seems turned on automatically. So, I disable (remove the checked) for this button. And....oh la la... it still doesn't work. However, we should not do like that because the message from SharePoint is not able to update "Cache". So, I tried to change the value CacheXslStorage="false" and ViewFlag="8", but it still end up with "Access denied".

However, i will work fine if there is an authenticated user view the blog detail first, then everybody can view this post without error. Maybe it's WAD or Bug of SharePoint 2010.

Update: We should not apply the cusomize xslt to ListXsltViewWebPart by UI in toolpane. We should open site by SPD, then change the property named "GhostedXslLink" is our customized xsl. This xsl is in layout/xsl folder of 14/hive. The content of this xsl file has reference to customized xslt.

Hope this help

Monday, October 10, 2011

Something in SharePoint (2007 & 2010)

There is a funny thing in SharePoint (in all versions)

1) List

With normal list the URL like http://server_name/site_name/Lists/List_Name
With documents list the URL like http://server_name/site_name/List_Name

2) Site

With normal site, all lists have the full controls on the list such as deleting, saving template,...
With blog site, the Posts list does not have permission to delete or save as the template and after save the blog site as template, we cannot restore the site correctly. All views of Posts list are generated as a list with the same name.

Friday, September 30, 2011

How to get all subsites if logged by Reader or Contributor

Sometime, we need to go through all sub-site of site collection to do something, however, it's very easy if you are logged in by Designer or Full Control. Because these account have full rights on subsites and the problem happens with Contributor or Reader. Look at the code:


SPWeb parent = SPContext.Current.Web;
foreach (SPWeb web in parent.Webs)
{
          try
          {
                    table.Merge(this.GetDataFromURL(new Uri(web.Url), schemaName, itemLimit));
           }
          catch (Exception ex)
         {
                //logger.Warn("DataBind::", ex);
         }
         finally
        {
              web.Dispose();
       }
}

The code runs without error but you will get the Access denied on the page and the stack trace shows full message like: "Unable to evaluate expression because the code is optimized or a native frame is on top of the call stack." That's very bad practice. Because of requirement, there are some subsites that Contributors or Readers do not have permission to read. However, we must get the data from remaining subsites which they have the right to read the data.

The code will change to:


SPWeb parent = SPContext.Current.Web;
parent.Site.CatchAccessDeniedException = false;
foreach (SPWeb web in parent.Webs)
{
          try
          {
                    table.Merge(this.GetDataFromURL(new Uri(web.Url), schemaName, itemLimit));
           }
          catch (Exception ex)
         {
                //logger.Warn("DataBind::", ex);
         }
         finally
        {
              web.Dispose();
       }
}


We need to set property "CatchAccessDeniedException = false" for SPSite object. SharePoint will know that catch any site does have permission to read. As a result, you never get "Access denied" exception on page but you also never get data correctly, because the collection of Webs will throw exception if any subsite strict from user does not have permission.

The best practice for this issue is to get all subsites which Current user has the right to read, the code to change again:


SPWeb parent = SPContext.Current.Web;
parent.Site.CatchAccessDeniedException = false;
foreach (SPWeb web in parent.GetSubwebsForCurrentUser())
{
          try
          {
                    table.Merge(this.GetDataFromURL(new Uri(web.Url), schemaName, itemLimit));
           }
          catch (Exception ex)
         {
                //logger.Warn("DataBind::", ex);
         }
         finally
        {
              web.Dispose();
       }
}


Method "GetSubwebsForCurrentUser()" of  SPWeb just gets all subsites which current user is to be able to access, atleast, reading the data.

Monday, August 29, 2011

Error Posts List when create a blog site from blog site template!

Haizzzzzzz...., I was so happy when I was working on SharePoint, especially is SharePoint 2010. But! Still But and But...SharePoint 2010 seems to be stopped if we could not find out the error and these issues are a WAD or not...nobody knows. And the HOTFIX is the best choice to solve the problem.

This time, I show you guys a simple issue but it was not fixed in June 2011 hotfix.

Step 1) Create a blog site. Design by yours, Customize by yours...Look nice.

Step 2) Save as a template to be used for the second time or another server...

Step 3) Import this template and create a new blog site base on this template.

ahahaha...:D Issue........

Open the newsite, then go to Site Action and View All Site contents. You will see:


And...what's happen then? You can work on new site as normal, but you cannot save the site template from new site, sharepoint will give you an error because many links blog are the same but actually it's the only one.

I am using foundation with the simplest configuration.

Any body helps me? /Thankssssss

Friday, July 22, 2011

Resolved: using [Today] in formula of Calculated column.

Situation:
I have a check list is listing the domain name of customers who registered the domain with my services. I need to know the remaining of the validation date and send to customer an email. The expiration day is calculated from due date until today.

Problem:
I created a list with Due Date column with DateTime formated. Another column called remain days belongs to calculated with the formula like this: [Due Date] - [Today]. After click save, I got an error:


That means, I can not use the SP variables, but I can define a custom column with the formula had an existed SP variable such as [Today] and [Me]. And I have another solutions:

1) Create a new column named Today with type of DateTime
2) Modify the Remains column if you had created before. Change the formula to [Due Date] - [Today] with [Today] is a new column.
3) Delete [Today] column.

As a result, the Remains column is calculated from Due Date to today.

Sunday, July 17, 2011

How to connect to MICROSOFT##SSEE (Windows Internal Database) - SharePoint 2010

In a previous post, I introduced the way how to connect to internal sharepoint database. But the limited is just supported for SharePoint 2010.

In SharePoint 2010, something changed in the structure of Database such as the instance name is SERVER\SHAREPOINT instead of SERVER\SQLEXPRESS or SERVER\OFFICESERVERS,... or something like that.

And it's easy to understand that internal database also gives the way easiest to connect to database, just replace the instance name in connnection string to "SHAREPOINT": \\.\pipe\MSSQL$SHAREPOINT\sql\query

Sunday, July 3, 2011

Installing and Configuring Bamboo Discussion Board Plus for SharePoint

In forum view, there are two parts: Sticky topics and normal topics. Some important topics need to be shown at the top of the Discussion Board. By selecting the topics as sticky they will be displayed at the top under Sticky Topics. Other topics will be shown under the Topics section. All topics are sorted by the Last Posted time. In addition, each of the sticky topics is marked as sticky with a sticky icon () to the left of the title.


Read more at: http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2011/07/01/installing-and-configuring-bamboo-discussion-board-plus-for-sharepoint.aspx

Saturday, June 25, 2011

Why Microsoft recommended that should not use Microsoft.Web.CommandUI.dll in any SharePoint products??

Almost asp controls of SharePoint has imported the namespace "Microsoft.web.commandui.dll" to manage the Ribbon. However, this dll wasn't recommended to use if you need to customize your Ribbon. To use the type or namespace of Ribbon, we should use "Microsoft.SharePoint.WebControls". Or course, in Microsoft.SharePoint.WebControls namespace also has implemented SPRibbon, but it's not enough.

Deassembly the WebControls namespace, SPRibbon only has some types, especially it does not have TrimById method, just Microsoft.Web.CommandUI.dll has.

I don't understand why Microsoft recommended that should not use this dll!??

Do not use types or members of the Microsoft.Web.CommandUI namespace for development within a SharePoint environment, but instead use SPRibbon and related types in theMicrosoft.SharePoint.WebControls namespace. For information about customizing the ribbon in SharePoint Foundation see Server Ribbon in SharePoint Foundation.

Anybody helps me?

Friday, June 24, 2011

Passed the examination 70-573: Microsoft SharePoint 2010, Application Development

I've decided to attend the examination 70-573 because I am working as Developer of SharePoint 2010.
It's not difficult for me because I had attended the Online Course:

and now it helps me a lot in my work, i feel better after finished learning the course and passed the examination. I will return to my blog in short day and continue sharing my knowledge about SharePoint 2007/2010.

Thanks for my co-worker helping.

Tuesday, June 21, 2011

Passed the examination 70-576: Designing and Developing Microsoft SharePoint 2010 Applications

I'm very happy to notice that I just passed the examination of 70-576.

A lot of skills need to be improved if you learn onlin at:

http://www.microsoft.com/learning/en/us/exam.aspx?id=70-576

Of course, that's very good document and orient the right way to pass the examination. After finish the online course you will learn the strongly knowledge to work with SharePoint 2010 with Design and Develop software based on SharePoint 2010.

Thanks again.

Thursday, May 12, 2011

What about the issue of Calendar in SharePoint 2007 show wrong datetime.

I decided to post this issue because I did not find out any wrong in my system, and if it is a WAD or Bug, please confirm this topic is correct and I will send this link to my customer.

Problem:

Install SharePoint 2007 with the default settings for everything. Create a celendar list and then create a column named "My Date Time" or something you want with DateTime type and show both Date and Time.

Create an item in Calendar with All Day Event checked, type a date into "My Date Time"

After save, everything is fine. Please see the picture in view form.

Title, AlldayEvent, My Test Datetime show correctly, data kept. But what is happening when I edit this item?


"My Test Datetime" was wrong, the date is minus 1 day and if I save this item, the data will store this date.

There is very strange that it will not change for the next editing. And this issue does not happen in SharePoint 2010

Tuesday, May 10, 2011

How to format datetime in SharePoint XSLT

In SharePoint (both of 2007 and 2010), Microsoft has implemented  XSLT 1.0 into CQWP (Content Query WebPart) and parse xsl file.

You can find out these file at 14\TEMPLATE\LAYOUTS\XSL, you will see some xsl files such as main.xsl, thread.xsl,... For now, you change reference version of xslt for these files, you will get an error because CQWP only understand the structure of XSLT 1.0. So, there are a lot of limitation to work on DateTime, String,...and other functionings of XSLT 2.0.

However, in SharePoint you can use an alias to get somes already formatted by using ddwrt namespance. Detail for more

It's very easy to use:

<xsl:value-of select="ddwrt:FormatDateTime('2010-may-25', 'G', 1033)"/>


First argument: Date original value
Second argument: Formatted expression, this argument has supported flag/string such as "d" (or 1) for date only as result as "M/d/yyyy"...
Third argument: regional setting. But no support for User Regional Setting


Thanks/

Wednesday, February 23, 2011

how to indicate the type of list definition?

I am working on list definition with the type id is 10001, my list is based on Calendar list.

But how can i indicate my list def is Events List or not?

Thanks for you helping!

Friday, February 18, 2011

Support discussion board list definition in VS2010 template

Visual Studio 2010 had supported List Definition  template to create the project automatically with fully the schema and define the structure of list. Unfonately, it has not supported for Dicussion Board list.

But you can download another template to upgrade your existed template and can use dicussion board list.

Download here

To use this package, please following this instruction:
  1.  Extract this pakage then copy all folders & files into: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplatesCache\CSharp\SharePoint\SharePoint14\1033\SharePoint14ListDefinition.zip
  2.  Copy this compressed file into: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates\CSharp\SharePoint\SharePoint14\1033
  3.  Please overwrite all files and folders as if request.
Good luck!



Monday, February 14, 2011

"Access denied. Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

Contribute account can access and some actions on the page. I created a new page with inheritance from the default.master of SharePoint 2010.

I tested on SharePoint 2007 and as a result it works smoothly. But in SharePoint 2010, I got an error:

"Access denied. Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"

The trace log:



It took me some hours to find out the problem, event thought I run the debugging line by line but it thows the exception before reach the CreateChildControl method. I guest it happens from ASPX or MasterPage.

Here is the problem:


 Some resources of this MasterPage can not be accessed by Contributor account, so just remove them out. Hope this help you fix your issue.

Sunday, February 13, 2011

"Access denied" when using contributor account to access to content-type

When I was using the contributor account to check the content-type folder is "message" or "Dicussion", I got an error: "Access denied!"

My code:

if (ctype.ResourceFolder.Name == "Message")
{
     //do something
}

But nothing happened with owner account.

Yes, because contributor account can not access to ResourceFolder properties of content-type. ResourceFolder was inherited from SPFolder and execute the method FolderEnsure. You know to give the access to folder ensure the account must be set the properties currentWeb.AllowUnsafeUpdates = true; and the default for member account does not have permission to run that update.

You can change the code to look like this:

if (ctype.Id == SPBuiltInContentTypeId.Message)
{
    //do something
}

The result is nearly the same.

Monday, January 24, 2011

How to get all items of Discussion Board list using Web Service.

Hello everybody,
I am working on Discussion Board list using Web Service. I am so supprised that the DB list is not the same as another list in SharePoint. The first sign of my mind is Calendar List Item, SharePoint stores the StartDate & EndDate with a different ways. To get the correctly data, we must understand clearly about architecture of Calendar list.

For now, the problem about Calendar was solved and faced to another problem. Discussion Board list has 2 item types: Dicussion (threads) and Message (replies). When you get all items by normaly, you only get the discussion items, take a look at code:


            XmlDocument document = new XmlDocument();
            XmlNode query = document.CreateNode(XmlNodeType.Element, "Query", "");
            
            XmlNode viewFields = document.CreateNode(XmlNodeType.Element, "ViewFields", "");


            XmlNode queryOptions = document.CreateNode(XmlNodeType.Element, "QueryOptions", "");
            queryOptions.InnerXml = "<ViewAttributes Scope='RecursiveAll'/>";


            Lists lists = new Lists(URL_SERVER);
            lists.Credentials = CredentialCache.DefaultCredentials;
            
            XmlNode node4 = lists.GetListItems(sourceList, "", query, viewFields, "", queryOptions);


Okey, even thought Scope attribute is set to "RecursiveAll", and SharePoint 2007 works fine. All items including reply items are list. But it does not work in SharePoint 2010, so it is not actually difficult to fix for SharePoint 2010. Just update your query CALM like the code below:


query.InnerXml = @"<Query>
                                <Where>
                                    <Geq>
                                        <FieldRef Name=""DiscussionLastUpdated"" />
                                        <Value Type=""DateTime"">1900-01-01T00:00:00Z</Value>
                                    </Geq>
                                </Where>
                               </Query>";
Yes, that's it.

Sunday, January 23, 2011

Show friendly error in SharePoint

Sometime, i dont know why my webpart (or site/page) happens error, event thought i turned off the CustomError tag in Web.Config

<CustomError mode="Off"/>

The default vallue of Mode is "ON", that means, SharePoint will show the error page liek this:

We've never known what about this error and also in the code there are any functions/methods give this issue. So, to let SharePoint show friendly the error and the stack trace of this error, we must change some values/attribute of tag in web.config.

1) Set Mode of <customerror> is Off

<CustomError mode="Off"/>

2) Find the tag <combilation> and change the value of debug is True

<compilation batch="false" debug="true">

3) In <SharePoint> tag, change the attributes of <SafeMode> to be:

<SafeMode MaxControls="200" CallStack="true" DirectFileDependencies="10" TotalFileDependencies="50" AllowPageLevelTrace="true">


Remember that doing reset IIS before press F5.


Now you can see your error as details and it's very easy to fix.