What are Sharepoint Content Types?
For me, one of the coolest new features of SharePoint Server 2007 (or MOSS) is Content Types. In this article, I’ll aim to give a brief overview of what they are and why you should be getting excited about them (especially if you are from a SharePoint 2003 background).
It is worth noting that this article is focused on the implications of Content Types in a document management scenario. Content Types are used throughout MOSS and have benefits throughout, but it was too much to cover in one article, so I decided to focus on DM.
What is a Content Type then?A content type is an object that is stored within MOSS that defines several elements of a piece of content, including:
- Document Template that the content will be based on
- Columns that the content will have associated with it (metadata)
- Workflows that the content will use
- Information Management policies that apply to the content
- Conversion types for the content
ASP.NET 2.0 Web Part Vs SharePoint based Web Part
ASP.NET 2.0 Web Part - For most business needs.
- To distribute your Web Part to sites that run ASP.NET 2.0 or SharePoint sites.
- When you want to reuse one or more Web Parts created for ASP.NET 2.0 sites on SharePoint sites.
- To use data or functionality provided by Windows SharePoint Services 3.0. For example, you are creating a a Web Part that works with site or list data.
SharePoint-based Web Part
- When you want to migrate a set of Web Parts using the SharePoint-based Web Part infrastructure to Windows SharePoint Services 3.0.
- To create cross page connections.
- To create connections between Web Parts that are outside of a Web Part zone.
- To work with client-side connections (Web Part Page Services Component).
- To use a data-caching infrastructure that allows caching to the content database.
-
SharePoint Database Structure and Its Usage
SharePoint uses SQL Server technology as to store information such as site configuration and site content. You should consider carefully whether you need to access the database directly or not. Microsoft has strongly suggested that we should not access data directly from the DB.
"Customers are strongly advised against direct access in a read-only manner to these DB unless Microsoft protocol documentation is followed exactly. Accessing these DBs programmatically or manually could cause unexpected locking within Microsoft SQL Server that can result in overall performance problems."
Many people out there in the community disagree that there are harm in reading data directly from the table as reading the database would cause no data change or its structure change.
Typically when SharePoint is first installed it generates two DB. One is configuration DB and the other one is the content DB. The configuration database normally has a default name of Sharepoint_config and and content has a default name of wss_contnet.
Sharepoint_config: this is the configuration db that contains information about the moss server, SQL Server, farm configuration, patches, updates, users, security, custom templates, features and etc. Typically it has around 24 tables. You can find more about what these tables does in this article.
WSS_Content: The content database typically holds information about activated features for site, site collections, web page information, users related to site, groups, roles, membership, user subscriptions, role assignment and etc.
Keep in mind that when updating the database directly always uses the SharePoint API object Model. Before doing any update consider doing a backup of the SharePoint database.
Move a list using a list template.
We can move a list using a list template.
1. Save the list as a template from the source list (make sure to include the contents)...save the template file on your local machine.
2. Import the template to the list templates gallery on the source site.
3. Create a list from the newly imported template.
4. Delete the template from the list templates gallery if you no longer need it.
Much easier...and like everything else that can be done through the UI.
Sharepoint CSS Options with Master Pages
SubmittedBy: CI-tech1
Description:
Skinning a SharePoint 2007 site with Master Pages is by no means and open/shut case of altering the look and feel of a site. There are some CSS inheritance issues that have to be contended with first.
As a quick refresher, styles applied to elements in a page will be styled according to the last property that was applied to it. An inline style will override a style listed in the HEAD tag or in a linked CSS file. Additionally, you can selectively override style properties by selectively listing what should be overridden. For example:
This overriding facet of CSS is key in SharePoint. Being 100% aware of what style sheets are called where can really help decrease the number of headaches you incur while trying to figure out why your custom styles are not appearing in your site.
Here is a general breakdown of how styles are pulled into a rendered SharePoint page in regards to master pages:
- If your master page links to a custom CSS file, the CSS file will get pulled BEFORE CORE.CSS.
- If your master page links to a CSS file, and CORE.CSS has been unghosted for the site, the custom CSS file will get pulled AFTER CORE.CSS.
- If you specify a custom CSS file in the Master Page settings (Site Actions/Site Settings/Master Page), the custom CSS file will get pulled AFTER CORE.CSS. Note: CSS overrides and new styles will also be applied to _layouts pages.
- Any styles listed or linked to in the PlaceHolderAdditionalPageHead ASP content placeholder will get pulled AFTER CORE.CSS. Problem with this approach is you will have to list your styles or link to your custom style sheet in every page layout file you create.
- Styles listed in the master page file (not linked to, actually listed out in a set of STYLE tags beneath the links to CSS files) will be called AFTER all links to CSS files, including CORE.CSS.
- Master pages deployed via a Feature will call CORE.CSS AFTER the custom CSS file(s).
- List the styles in the master page file
- Link to the style sheet through Master Page settings
- Include the styles in the PlaceHolderAdditionalPageHead ASP content placeholder in your page layout files
- Unghost CORE.CSS for the site. I don't recommend this.
Set up announcements to disappear from the screen when they pass their expiration date
SubmittedBy: CI-tech1
Description:
Note: This does not apply to the expanded view of the announcements web part. In the expanded view you can still access all announcements until they are permanently deleted manually.
- For Portal: Select Edit Page under the Actions menu; Select the arrow to the right of the announcements title bar and select Modify Shared Web Part.
For WSS Site: Select the arrow to the right of the announcements title bar and select Modify Shared Web Part. - Under Selected View, select Edit the Current View.
- Under Filter, select these options:
- Select Show items only when the following is true:
- Under Show the items when column, in the first drop down select Expires.
- In the second drop down select is greater than or equal to.
- In the field, enter [Today].
- Select OK.
-
MOSS Enterprise Search - 16 things you might not know
SubmittedBy: CI-tech1
Description:
Hello everybody \o/ - a few bits and pieces you might find useful when designing and deploying Enterprise Search based on Office SharePoint Server 2007 .Really interesting things
- On document libraries which support approval, users might be able to search and view abstracts for unpublished content which they would otherwise not be able to see. This happens if the crawler account has permission to view drafts, which is separate from any security trimming which will be applied. Using an account with only reader permissions would prevent this, but conversely a user with rights to see draft content could only search content from the last published version. Since the files share a URL it's either one or the other - a decision to be made by your customer.
- Keyword search has moved from implicit OR to implicit AND as standard, although this can be configured on calls through the web service. Additionally, if you use the Advanced Search, which in effect creates a SQL query, you can specify to AND or OR your requests as well as wildcard your keywords, etc.
- Only a full crawl will re-index ASPX files. Therefore, if you have removed documents from a document library, the library may still appear in the results if you search for the document name after an incremental crawl.
- There is a tested recommended maximum of 4 SSPs per farm, and a hard limit of 20.
- The tested recommended maximum is 50 million documents across all content sources in an index. Since you can have only one index server per Shared Services Provider, the recommended approach for more capacity is to add another SSP. There is no supported way to union the results. Don't forget BDC items count to your total.
- There is a hard limit of 500 start addresses per content source. If the default content source is full, additional new sites will not have their start addresses registered (anywhere), so you'll need to add them manually to another content source, or change the default content source.
- Information about the size of search indexes and search databases relative to corpus size is due to be released on Technet shortly.
- Since the Indexer crawls a Web Front End for SharePoint content, in a load balanced scenario, any of the Web Front End servers could get hit. You can override this and specify a single WFE for the Indexer to use. In this case, you could exclude this from the load balancer and have it as a dedicated WFE for indexing.
- Query and Index roles can run on the same server. However, to add extra Query servers, the Indexer must run alone. E.g. you would scale out from Query+Index on one server to Index on one server and Query on two servers.
- Collapsing your WFE and Query roles onto the same server can improve query performance, especially when custom security trimmers are used on the WFEs to iterate over the results.
- Architectures can be mixed between roles (e.g. 32bit WFE, 64bit Indexer) but not in the same role.
- 64bit is recommended for the Indexer, but most custom IFilters, like Adobe PDF, don't support this new platform just yet.
- The default maximum file size the Indexer will download and parse is 16mb. This is a registry entry on the Indexer - one to update if customers deal with large PowerPoint slidedecks etc.
- Search term word stemming is off by default. You can enable this in the Core Search Results web part, but it may skew the new improved ranking mechanism.
- Search usage reports gather data from client side asynchronous JavaScript when a user selects a result from the results page. Therefore, reports don't show search terms used through the API or the Query Web Service.
- It's kind-of obvious, but forms authentication to external websites is not supported for crawling.
Fill Dropdown List with SharePoint List Items
protected void Page_Load(object sender, EventArgs e)
{
SPSite mySite = new SPSite(“http://server/sites/site“);
SPWeb myWeb = mySite.OpenWeb();
{
SPList myList = myWeb.Lists["ListNameHere"];
foreach (SPListItem listRecords in myList.Items)
{
ListItem tempItem = listRecords["FieldNameHere"].ToString();
ddlFromSPList.Items.Add(tempItem); //ddlFromSPList is the name of the dropdown list
}
}
}
———————————————————————————————————————————————
private void buildList(DropDownList list, DataSet myDataSet)
{
foreach(DataColumn dCol in myDataSet.Tables[0].Columns)
{
if (dCol.ToString() != “”)
{
ListItem tempItem = new ListItem(dCol.ToString());
list.Items.Add(tempItem);
}
else
{
break;
}
}
}
Creating Custom Templates
Now that we know that custom templates track changes to a SharePoint site definition, we can examine the different types of custom templates. List templates track changes to columns, forms, pages, and optionally, changes to the content associated with a specified list. Site templates track changes to site navigation, Web Parts, lists present on a site, and optionally, changes to the content of a single site. You can save an existing site as a site template.
A custom template is persisted as a file with an .stp extension, which is actually a .cab file that you can rename with the .cab file extension and open in Windows Explorer. This file includes one Manifest.xml file in Collaborative Application Markup Language (CAML) that the server generates as a subset of the Microsoft SharePoint Migration Tool (Smigrate.exe) manifest file format.Note There is a 10 MB quota on the total size of the content you can store in a site template. You can determine the size of site content by going to Top-Level Site Administration, and in the Management and Statistics section, clicking View site usage data.
Let's say that you created a site, customized it by adding lists, events, document libraries, custom Web Parts, and applied a special theme. You want to share this piece of work with other site owners or impose this site template on any subsites. On the Site Settings menu, click Go to Site Administration, and then in the Management and Statistics section, click Save as template. Type a file name using an .stp extension and type a title and description for your site template. You can also select the Include content check box. You save your site as a template in a gallery inside the content database to make it available to other subsites. As long as subsequent subsites are based on the same site definition (for example, on a Document Workspace) and have the identical language of the original site, you can create subsites using this template.
To make the template appear in the list of templates in the Site Creation wizard, you need to export the template to the file system and run the STSADM command tool. To export the template, right-click the template and click Save Target As, and then follow the prompts to save the template. After saving the template to the file system, from a command prompt, type the following:
stsadm.exe -o addtemplate -filename "local_drive:\site_template_file_name.stp" -title "Site_Template_Name"
You can also export a list template the same way you exported the site template. However, list templates are available only to the site collection of the site from which you exported.Note You must reset Microsoft Internet Information Services (IIS) before these changes can take affect. After resetting IIS, the Site_Template_Name template becomes available in the site template list during site creation.
Resolving the "Unable to display this Web Part" problem after SharePoint Designer restore
SubmittedBy: CI-tech1
Description:
If you've restored the SharePoint site using commands Site --> Administration --> Restore site and this site had special XSLT data views you may be in for a big surprise!You can receive the following message:Unable to display this Web Part. To troubleshoot the problem, open this Web page in a Windows SharePoint Services-compatible HTML editor such as Microsoft Office SharePoint Designer. If the problem persists, contact your Web server administrator.Or in Slovene languageSpletnega gradnika ni mogoče prikazati. Če želite odpraviti težavo, odprite spletno stran v urejevalniku HTML, združljivim s storitvami Windows SharePoint Services, kot je program Microsoft Office SharePoint Designer. Če težave ne morete odpraviti, se obrnite na skrbnika spletnega strežnika.The problem is that while restoring the site, SharePoint designer doesn't correct the GUIDs of lists being used. For example: You're having an XSLT data view of a list called Contacts. When restoring SharePoint designer creates the list with a new GUID, but it uses the old GUID (from where the backup was made) of the list. The solution is simple: Fix the GUIDs of lists used in dataviews:1. Open the Manage content administration page of your site (http://server/site/_layouts/mcontent.aspx)2. Copy the shortcut of the list being used in XSLT to clipboard
3. In the URL you'll find the new GUID of a list between brackets ( in http://server/site/_layouts/ListEdit.aspx?List={89D731E5-0538-4999-B4AF-D7A5D9EA781F} the GUID is 89D731E5-0538-4999-B4AF-D7A5D9EA781F4. With SharePoint Designer open the page with XSLT data view and search for term ListID in the code.5. Select the value of the ListID parameter. It should be the GUID of the list (either in ListID="....." or in the same tag, look for GUID-like numbers.6. Prest CTRL+H for Search and Replace with the value still selected. It will automatically populate the "Find what" field with it. Now paste the copied URL with GUID in the "Replace with" field and remove all but the GUID. Make sure you have the "Find in Source Code" option checked.7. Now just press the "Replace all" button and your XSLT data view will magically come to life :).I hope that this bug will be fixed with next version of SharePoint Designer, or maybe can develop some kind of plugin for that procedure to speed up the process for all the pages. I know that with FrontPage this wasn't happening.Technorati tags: sharePoint, backup, restore, SharePoint Designer, Data View, XSLT, GUID
How to Activate the Drop Down Menu in MOSS Sites
SubmittedBy: CI-tech1
Description:
MOSS 2007 sites can display drop down menus in the tabbed navigation across the top. Unfortunately there is not an easy check box to activate this functionality, instead things just have to be set up the right way. If you want your MOSS site to show drop down menus, make sure the following is true or walk through the following steps:- From the root of the parent site (Home) choose to create a new site (Site 1). Once that site is created, you will be in that new site. From here choose to create a new page.
- Once that is created, choose to create another new site (Sub Site 1). Then create a new page in Sub Site 1.
- Your site structure should resemble this.
- For each site in the Navigation settings, both Show Subsites and Show Pages should be checked.
- Select Site Actions - Site Settings - Modify Navigation.
- Check Show subsites and Show pages in the first row.
- Select Site Actions - Site Settings - Modify Navigation.
- The end result would be a tab in the horizontal bar for Site 1, with a vertical drop showing Sub Site 1.
The navigation shows sub sites under the parent and published pages at the parent. Pages for one site are stored flat in a single library. If you want the navigation to show 2nd level sub site pages or 3rd level sub sites under the 2nd level, you need to make a very minor tweak to the master page that the site is using.- Using SharePoint Designer (SPD), open the master page being used by the site. Warning! Making edits to this file will customize the file, a.k.a. unghost it. Don't worry you can always undo this action.
- In SPD, navigate to _catalogs/masterpage/*.master
- How do you know which master the site is using? In the site, go to Site Actions - Site Settings - Modify All Settings, then choose Master page under the Look and Feel column. Check which master page is selected in each drop down.
- In SPD, navigate to _catalogs/masterpage/*.master
- In the master page file, search for SharePoint:AspMenu.
- You will more than likely have more than one instance of a menu control. Look at the IDs to find the right navigation control for what you want to edit. They are intelligently named, you will be able to sort out which one you need. For default.master, look for ID="TopNavigationMenu".
- You will more than likely have more than one instance of a menu control. Look at the IDs to find the right navigation control for what you want to edit. They are intelligently named, you will be able to sort out which one you need. For default.master, look for ID="TopNavigationMenu".
- In the properties for the tag, find MaximumDynamicDisplayLevels="1". Change the number from 1 to 2.
- Save the file and publish the master page (do this from SPD, Manage Content and Structure, or the Master Page Gallery).
- Refresh your browser. Now when you mouse over Site 1 - Sub Site 1, you should see another level of navigation pop up.
Cool, ehh? Please don't abuse this dynamic display level. As tempting as it is to provide instant access to something 5 levels deep in your site, drop down menus notoriously aggravate end users. I highly recommend using no more than 2 levels (what we set in this walk through).
1.Programming SharePoint Object Model, Web Services, and Events
SubmittedBy: CI-tech1
Description:
-
Programming SharePoint Object Model, Web Services, and Events -
Summary of .NET support-
SharePoint will use ASP.NET instead of ISAPI for base page execution -
Web Part Framework -
Server Object Model for programmatic access to SharePoint data -
We offer functionality as XML web services for access from remote machines
-
-
.NET Object Model-
Managed code object model on the server -
Accessible via ASP.NET or any other server process -
Implemented in C# -
Exposes almost of all of the data stored in WSS
-
-
NET Object model-
Examples of what can be done with the Object Mode:-
Add, edit, delete, and retrieve data from SharePoint Lists -
Create new lists and set list metadata (e.g. the fields in a list) -
Set web properties -
Work with documents in document libraries. -
Perform administrative tasks such as creating webs, adding users, creating roles, etc. -
Pretty much any functionality in the UI can be automated through the OM!
-
-
-
Example Objects-
List Data-
SPField -
SPFieldCollection -
SPListCollection -
SPList -
SPListItemCollection -
SPListItem -
SPView
-
-
Administration-
SPGlobalAdmin -
SPQuota -
SPVirtualServer
-
-
Security-
SPGroup -
SPGroupCollection -
SPSite -
SPUser -
SPUserCollection
-
-
Documents-
SPDocumentLibrary -
SPFile -
SPFileCollection -
SPFolder
-
-
-
ASP.Net Security-
For content stored in WSS, only registered set of web custom controls will run in pages -
Inline script in the page will not execute-
Code behind in pages can be made to work
-
-
All Executable code (e.g. web custom controls, web parts, and code-behind classes) needs to be installed on physical web server
-
-
Getting Started with OM-
Build a web part-
This is the best option to write code that functions are part of a WSS site or solution -
There will be lots of documentation with the beta on how to build a web part. -
Web Part is reusable and can be managed using all of the web part tools and UI.
-
-
-
Getting Started with the OM-
Build an ASPX page-
Code cannot live inline in a page within the site. -
Creating pages underneath the /_layouts directory is often the best option for custom ASPX apps on top of SharePoint-
This lets your page be accessible from any web. For example, if you build mypage.aspx in _Layouts, it is accessible from the following URLs:-
http://myweb/_layouts/myapp/mypage.aspx -
http://myweb/subweb1/_layouts/myapp/mypage.aspx
-
-
ASPX page will run using the context of the web under which it is running.
-
-
-
-
Getting Started with the OM-
Windows Executable or any other application-
Object model can be called from pretty much any code context. It is not limited to just web parts or ASP.Net -
For example, you could build a command-line utility to perform certain actions
-
-
-
Demo-
Hello World Web Part
-
-
Working with the OM-
The object model has three top-level objects:-
SPWeb (represents an individual site) -
SPSite (represents a site collection, which is a set of web sites) -
SPGlobalAdmin (used for global administration settings)
-
-
In order to perform actions on data within a web, you must first get an SPWeb object.
-
-
Adding our namespace-
You should add references to the WSS namespaces to your source files-
using Microsoft.SharePoint; -
using Microsoft.SharePoint.WebControls; -
using Microsoft.SharePoint.Administration; -
…
-
-
-
Key Object – SPWeb-
Starting point to get at the Lists, Items, Documents, Users, Alerts, etc. for a web site. -
Example Properties:-
Web.Lists (returns a collection of lists) -
Web.Title (returns the title of the site) -
Web.Users (returns the users on the site)
-
-
In a web part or ASPX page, you can use the following line to get a SPWeb:-
SPWeb myweb = SPControl.GetContextWeb(Context);
-
-
-
Demo-
Showing Web and List Properties
-
-
Accessing data in a WSS List-
Get a SPList or SPDocumentLibrary object.-
SPList mylist = web.Lists[“Events”];
-
-
You can then call the .Items property to get all of the items:-
SPListItemCollection items = mylist.Items;
-
-
If you only want a subset of the items, call the GetItems method and pass a SPQuery object-
SPListItemCollection items = mylist.GetItems(query);
-
-
-
Accessing data in a list-
To get data for a field, specify the field name in the indexer for an SPListItem-
foreach(SPListItem item in items) -
{ -
Response.Write(item["Due Date"].ToString()); -
Response.Write(item["Status"].ToString()); -
Response.WRite(item["Title"].ToString()); -
}
-
-
-
Full Example-
SPWeb web = SPControl.GetContextWeb(Context); -
SPList tasks = web.Lists["Tasks"]; -
SPListItemCollection items=tasks.Items; -
foreach(SPListItem item in items) -
{ -
output.Write(item["Title"].ToString() + item["Status"].ToString() + "
"); -
}
-
-
Updating data-
Most objects in WSS do not immediately update data when you change a property -
You need to first call the Update() method on the object-
This helps performance by minimizing SQL queries underneath the covers
-
-
Example:-
SPList mylist = web.Lists[“Tasks”]; -
mylist.Title=“Tasks!!!”; -
mylist.Description=“Description!!”; -
Mylist.Update();
-
-
-
Updating List Data-
SPListItem is another example of an object where you need to call update: -
Example:-
SPListItem item = items[0]; -
item["Status"]="Not Started"; -
item["Title"]="Task Title"; -
item.Update();
-
-
-
FormDigest Security-
By default, the object model will not allow data updates if the form submitting the data does not contain the ‘FormDigest’ security key. -
FormDigest is based on username and site. It will time out after 30 minutes. -
Best solution is to includeweb folder control in ASPX page. -
If you do not need the security the FormDigest provides, you can set to SPWeb.AllowUnsafeUpdates to bypass this check.
-
-
Adding Users to a web-
Get the appropriate SPRole object: -
SPRole admins = web.Roles["Administrator"]; -
Call the AddUser method: -
admins.AddUser("redmond\gfoltz","Greg@hotmail.com","Greg Foltz","");
-
-
Demo-
Adding users to the site via the OM
-
-
Keep objects around-
If you create and destroy objects frequently, you may do extra SQL queries and have code that is incorrect: -
Bad Example:-
SPWeb web = SPControl.GetContextWeb(Context); -
web.Lists["Tasks"].Title="mytitle"; -
web.Lists["Tasks"].Description="mydescription"; -
web.Lists["Tasks"].Update();
-
-
Good Example:-
SPWeb web = SPControl.GetContextWeb(Context); -
SPList mylist = web.Lists["Tasks"]; -
mylist.Title="mytitle"; -
mylist.Description="mydescription"; -
mylist.Update();
-
-
SharePoint will have web services APIs for accessing content. The web services layer will be built on top of the server OM. -
Allows manipulation of Lists, Webs, Views, List Items, etc. -
Functionality will be similar to server object model, but with fewer interfaces optimized to minimize transactions. -
Office11 (e.g. Excel, DataSheet, Work, Outlook, FrontPage, etc) use web services to access data from WSS.
Web Services in WSS -
-
Web Service Methods-
GetListCollection -
GetListItems -
GetWebCollection -
UpdateList -
UpdateListItems -
GetWebInfo -
GetWebPart -
GetSmartPageDocument -
And more…
-
-
Getting Started With Web Services-
Create a Windows Application -
In Visual Studio, choose ‘Add Web Reference’-
Enter http:///_vti_bin/lists.asmx to access the lists web service -
Other services include:-
UserGroups.asmx – users and groups -
Webs.asmx – Web information -
Views.asmx – View information -
Subscription.asmx – Subscriptions
-
-
-
-
Getting Started with Web Services-
To send the logged on users’ credentials from the client, add the following line in the web reference object’s constructor:-
public Lists() { -
this.Url = "http://mikmort3/_vti_bin/lists.asmx"; -
this.Credentials=System.Net.CredentialCache.DefaultCredentials; -
}
-
-
-
Demo-
Building a Web Service Client
-
-
Events-
We support events on document libraries.-
Operations such as add, update, delete, check-in, check-out, etc. -
Events are asynchronous -
Events call IListEventSink managed interface.
-
-
Documentation and Sample in the SDK
-
-
Optimizing Performance of OM-
The biggest goal is to minimize the number of SQL queries.-
It may be helpful to use the SQL profiler to monitor what the OM is doing underneath the covers
-
-
Minimizing managed/unmanaged transitions also a goal, though this is mostly taken care within the OM.
-
-
What about CAML?-
Page Execution will no longer be driven by CAML (XML schema used in SharePoint) -
CAML is still used in several places-
Field Type Definitions -
Site and List Templates -
View definitions
-
-
-
SDK Available-
Documentation about V2 available at http://msdn.microsoft.com/sharepoint/
-
-
Questions? -
-
Code Example -- Enumerate Lists and Webs-
private void ShowSubWebs(HtmlTextWriter output) -
{ -
SPWeb web = SPControl.GetContextWeb(Context); -
SPWebCollection mywebs = web.Webs; -
foreach (SPWeb myweb in mywebs) -
{ -
output.Write(myweb.Title + "
"); -
} -
} -
private void ShowSubWebsWithLists(HtmlTextWriter output) -
{ -
SPWeb web = SPControl.GetContextWeb(Context); -
SPWebCollection mywebs = web.Webs; -
foreach (SPWeb myweb in mywebs) -
{ -
output.Write("" + myweb.Title + "
" + ""); -
SPListCollection lists = myweb.Lists; -
foreach (SPList list in lists) -
{ -
if (list.ItemCount>10) -
{ -
output.Write(list.Title + ": " + list.ItemCount + "
"); -
} -
} -
} -
}
-
-
Code Snippet – Copy Files-
private SPWeb web; -
private void Page_Load(object sender, System.EventArgs e) -
{ -
web = SPControl.GetContextWeb(Context); -
} -
private void Button1_Click(object sender, System.EventArgs e) -
{ -
int maxsize = Convert.ToInt32(TextBox1.Text); -
SPFolder myfolder=web.GetFolder("Shared Documents"); -
SPFileCollection myfiles = myfolder.Files; -
foreach (SPFile file in myfiles) -
{ -
if (file.Length>(maxsize*1024)) -
{ -
Response.Write(file.Name + ": " + file.Length/1024 + "kb
"); -
file.CopyTo("Archive/"+file.Name,true); -
} -
} -
}
-
-
Code Snippet – Add users-
private void Button1_Click(object sender, System.EventArgs e) -
{ -
SPWeb web = SPControl.GetContextWeb(Context); -
string username = TextBox1.Text; -
string displayname = TextBox2.Text; -
string email = TextBox3.Text; -
SPRole admins = web.Roles["Administrator"]; -
try -
{ -
admins.AddUser(username,email,displayname,""); -
Label4.Text="Successfully added user"; -
} -
catch(Exception ex) -
{ -
Label4.Text=ex.ToString(); -
} - }
-
No comments:
Post a Comment