It has great capabilities on the SharePoint platform. Many of us just have time to learn how basic SharePoint APIs work, such as websites, networks, lists, files, features, and solutions, workflow, event receiver, Web parts and some others. Then, because of the tight schedule, we often start to build the core SharePoint APIs, instead of trying to find out whether they have been implemented in our auxiliary methods. Some methods established with these customers are actually provided in SharePoint.
This post is about the first type, which is often forgotten or even unknown, but some useful methods are exposed. This is the Microsoft. SharePoint. Utility. SPUtility class. I want to show you some of its good stuff.
Let's start with the following two:
public static string GetUrlDirectory(string url);public static string GetUrlFileName(string url);
How many times have you manipulated the URL to get only partial file names or folder paths? I keep wondering why the URL versions of System. IO. Path. GetFileName () and System. IO. Path. GetDirectoryName () are different. NET Framework. The above method is just doing this, they are both relative and absolute URL server work. This is true. Their implementation is very simple, but why should they do it by themselves? Remember the two for the next time.
The other two routines enable you to display the message that the operation result is successful or failed:
SPUtility. TransferToErrorPage ("Error from SPUtility !"); // Jump to _ layouts/error. aspxSPUtility. TransferToSuccessPage ("Hello from SPUtility !"); // Jump to _ layouts/success. aspx
When you call them, SharePoint will display the "Operation completed successfully" page or "error" Page, without customizing the successful and error pages by yourself. Is it good?
This is another big problem, but I don't like some clever display emails and only need a line of code. You can also specify the URL, and the browser will navigate to when the user clicks OK.
Sometimes you may need to open files under the 12 directory. Whether it is your own or SharePoint configuration file or another file. If you have always hardcoded the 12 directory, such as C: \ Program Files \ Common Files... and then stop doing this! The following function returns the complete sub-Folder path under the 12 directory.
public static string GetGenericSetupPath(string strSubdir);
For example, calling GetGenericSetupPath ("Config") will return the complete path of the config folder under the 12 directory. Remember that the installer path is not necessarily in the C drive or non-English Program Files, but is not called "Program Files", so start using this function! (GetGenericSetupPath function)
A great way! You Need To Know AllowUnsafeUpdates
public static bool ValidateFormDigest();
This will verify the form of your post to digest the requirements, you do not have to worry about the future SPSite new instance AllowUnsafeUpdates.
It takes some time to look at other methods in the SPUtility class. You may find other things useful.
You can also use SPUtility to directly send emails ....
Original English link: Don't Forget SPUtility
Technorati labels: SPUtility, moss, sharepoint, GetUrlDirectory, GetUrlFileName, TransferToErrorPage, TransferToSuccessPage, ValidateFormDigest