Hello All,
Below code snippet shows how to create a sharepoint site Programmatically.
SPSite oSiteCollection = new SPSite("http://Your Server name/");
SPWeb oWebSite = oSiteCollection.OpenWeb();
oWebSite.AllowUnsafeUpdates = true;
SPWebCollection oSitesCollection = oWebSite.Webs;
SPWeb newWebSite = oSitesCollection.Add("MySPSite", "My SharePoint Site Created Through Code", "This is site created through code.", 1033, "STS#1", true, false);
Thats't it...your dynamic site is now ready..!
For reference of Site Templates refer below:
STS#0
Team Site
STS#1
Blank Site
STS#2
Document Workspace
MPS#0
Basic Meeting Workspace
MPS#1
Blank Meeting Workspace
MPS#2
Decision Meeting Workspace
MPS#3
Social Meeting Workspace
MPS#4
Multipage Meeting Workspace
WIKI#0
Wiki
BLOG#0
Blog
For Locale ID, refer :
http://msdn.microsoft.com/hi-in/goglobal/bb964664(en-us).aspx
Hope it helps...
Thanks,
Nitin Sharma
Wednesday, December 30, 2009
Programmatically upload a file to a document library in Sharepoint
Hi All,
Below code snippet upload a Doc file(any document) into the document library of a sharepoint site programmatically.
SPSite site = new SPSite("http://YourServerName/YourSite/");
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
if (FileUpload2.HasFile)
{
SPFolder myLibrary = web.Folders["YourDocumentLibrary"];
String Filename = Path.GetFileName(FileUpload2.PostedFile.FileName);
FileStream fs = File.OpenRead(FileUpload2.PostedFile.FileName);
SPFile spFile = myLibrary.Files.Add(Filename, fs, true);
myLibrary.Update();
}
Hope it helps you all Sharepoint guys...
Thanks,
Nitin Sharma
Below code snippet upload a Doc file(any document) into the document library of a sharepoint site programmatically.
SPSite site = new SPSite("http://YourServerName/YourSite/");
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
if (FileUpload2.HasFile)
{
SPFolder myLibrary = web.Folders["YourDocumentLibrary"];
String Filename = Path.GetFileName(FileUpload2.PostedFile.FileName);
FileStream fs = File.OpenRead(FileUpload2.PostedFile.FileName);
SPFile spFile = myLibrary.Files.Add(Filename, fs, true);
myLibrary.Update();
}
Hope it helps you all Sharepoint guys...
Thanks,
Nitin Sharma
Add pictures to the Pictures library in Sharepoint Programmatically
Guys,
This code snippet adds a Picture to the Picture library of the sharepoint site Programmatically.
SPSite Site = new SPSite("http://Your Server Name/YourSite/");
SPWeb web = Site.OpenWeb();
web.AllowUnsafeUpdates = true;
Stream StreamImage = null;
if (FileUpload1.HasFile)
{
StreamImage = FileUpload1.PostedFile.InputStream;
}
SPList pics = web.Lists["Nitin's Picture Library"];
pics.RootFolder.Files.Add(FileUpload1.FileName, StreamImage);
That's it....
Hope it helps...
Thanks,
Nitin Sharma
Tuesday, December 29, 2009
Get Date of All Weekdays or Weekends of the Year
Hi guys,
I was going through the Pinal Dave's Blog today...He has posted a wondeful post today ....You guys may find it very very useful...
The topic is Get Date of All Weekdays or Weekends of the Year.
http://blog.sqlauthority.com/2009/12/29/sql-server-get-date-of-all-weekdays-or-weekends-of-the-year/
Thanks,
Nitin Sharma
I was going through the Pinal Dave's Blog today...He has posted a wondeful post today ....You guys may find it very very useful...
The topic is Get Date of All Weekdays or Weekends of the Year.
http://blog.sqlauthority.com/2009/12/29/sql-server-get-date-of-all-weekdays-or-weekends-of-the-year/
Thanks,
Nitin Sharma
Create Custom Task in MOSS 2007
Guys..Below you can find the script to add custom Task in MOSS 2007 and assigned to a user.
protected void Button1_Click(object sender, EventArgs e)
{
try
{
using (SPSite site = new SPSite(http://YourServerName/YourSite))
{
site.AllowUnsafeUpdates = true;
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList TaskList = web.Lists["MyTasks"];
SPListItem NewTask = TaskList.Lists["MyTasks"].Items.Add();
NewTask["Priority"] = DropDownList2.SelectedValue;
NewTask["Title"] = TextBox1.Text;
NewTask["Description"] = TextBox3.Text;
NewTask["Assigned"] = DropDownList1.SelectedItem.Value;
NewTask.Update();
}
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
Hope u find it useful...!!!!
Thanks,
Nitin Sharma
protected void Button1_Click(object sender, EventArgs e)
{
try
{
using (SPSite site = new SPSite(http://YourServerName/YourSite))
{
site.AllowUnsafeUpdates = true;
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPList TaskList = web.Lists["MyTasks"];
SPListItem NewTask = TaskList.Lists["MyTasks"].Items.Add();
NewTask["Priority"] = DropDownList2.SelectedValue;
NewTask["Title"] = TextBox1.Text;
NewTask["Description"] = TextBox3.Text;
NewTask["Assigned"] = DropDownList1.SelectedItem.Value;
NewTask.Update();
}
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
}
Hope u find it useful...!!!!
Thanks,
Nitin Sharma
Subscribe to:
Posts (Atom)