Tuesday, May 26, 2009

Send Document as Attachement Feature

Send document as attachment feature is useful in ECB menu to send email with current document as attachment.

You can download full code from codeplex.
http://trushar82.codeplex.com

Feature is look like below snap.







Monday, May 18, 2009

Custom Action link in listedit page in sharepoint

Feature.xml

<Feature Id="90CCFF3E-0874-441b-B430-1920BAF59B08"
Title="My Permission Link"

Version="1.0.0.0"
Scope="Web"
Hidden="false"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests >
<ElementManifest Location="element.xml" />
</ElementManifests>
</Feature>


element.xml

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<CustomAction Id="39C18565-C185-4353-8025-E15859E3C4F3"
GroupId="Permissions"
Location="Microsoft.SharePoint.ListEdit"
Sequence="100"
Title="My Permission Link"
>

<UrlAction Url="_layouts/custom/MyRecycleBinItems.aspx" />

</CustomAction>
</Elements>


If you want add link in general settings then add
GroupId as GeneralSettings.

Thursday, May 14, 2009

Sharepoint Control - Object Model

Below is link which one use sharepoint object model as well as web part.

Sharepoint WebControl

Monday, May 11, 2009

Set current date in sharepoint DateTimeControl using Object Model

Below is a code to set current date in sharepoint dateTimeControl using object model.

dtdemodate.selectedDate=Now.Today.date.Tostring();

Export To Excel in Sharepoint

Today I have facing problem in my user control web part when i exported grid view data into excel.

Error is like "control not load at form server tag".

I have created new ASPX page and generate grid and write code for export to excel.
After put this control into sharepoint 12 hive folder like "_Layout".

I have added Page View web part in page and added property link like "http://localhost/_layout/exportToExcel.aspx".

So its working fine.
Put following code in ASPX page.

public override void VerifyRenderingInServerForm(Control control)

{

}

Tuesday, May 5, 2009

Upload File/Document in DocLibrary/List using Sharepoint Object Model

using (SPSite site = new SPSite("http://localhost"))
{

using (SPWeb web = site.OpenWeb())
{

SPList list = web.Lists["MyList"];
web.AllowUnsafeUpdates = true;
SPListItem item = null;
item = list.Items.Add();

item["Title"] = "Test by Tushar";
string fileName = "";
if (File1.PostedFile != null)
{
Stream fStream = File1.PostedFile.InputStream;

byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
fStream.Dispose();

SPAttachmentCollection attachments = item.Attachments;
fileName = Path.GetFileName(File1.PostedFile.FileName);
attachments.Add(fileName, contents);

}

item["FileName"] = fileName;
item.Update();



}