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

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

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

Thursday, December 17, 2009

Steps to Install MOSS 2007 in Windows Server 2008

Hi All,
I found this article very great where it shows the steps to install MOSS 2007 in windows server 2008:

Here is the URL : http://mindsharpblogs.com/ben/archive/2007/12/16/3837.aspx

Thanks Ben Curry..!



Hope this article helps to u also...

ba bye....