Sharepoint Book Search

Loading

Visual Studio 2008 - how to enable web application templates in class project

Sometimes it is required that we create a class project and then add controls from other project types.. e.g. for sharepoint development we may want web pages available in a class project.



Following are the steps to do so..
1. Unload the project


2. For C# projects add the following
{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
For VB.Net
{349c5851-65df-11da-9384-00065b846f21};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}





3. Reload the project. You should now see all the web item templates.

How to get values from 'Person or Group' or 'Lookup' field

SPListItem item; 
.... 

// To get value from 'Person or Group' field 
SPFieldUserValue fieldValue = (SPFieldUserValue)item.Fields["Agent"].GetFieldValue((string)item["Agent"]); 

//Sometimes it is possible that the field display name is different that the internal name.. 
// in this case use the internalname
SPFieldUserValue AssignedToValue = (SPFieldUserValue)item.Fields.GetFieldByInternalName("Assign_x0020_to").GetFieldValue((string)item["Assign_x0020_to"]);


//To get value from 'Lookup' field 
SPFieldLookupValue jobValue = (SPFieldLookupValue)item.Fields["Job"].GetFieldValue((string)item["Job"]); 

Tooltip Balloon

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml/DTD/xhtml-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

 

<head>

<!--

     Derrived from the work of Eric Meyer

http://www.meyerweb.com/eric/css/edge/popups/demo.html

     -->

<meta http-equiv="content-type" content="text/html;charset=iso-8859-1">

<title>| mikezilla | CSS Rollovers for tooltips</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<!--

<script type="text/javascript" src="mikezilla.js"></script>

<link rel="stylesheet" type="text/css" media="screen" title="" href="mikezilla-exp.css">

-->

 

<style type="text/css">

body {font: normal 14px/20px verdana;}

a:hover {background-color: #333;color:#fff;}

p.link a:hover {background-color: #2B2E21;;color:#fff;}

p.link a:link span{display: none;}

p.link a:visited span{display: none;}

p.link a:hover span {

position: absolute;

margin:15px 0px 0px 20px;

background-color: beige;

max-width:220;

padding: 2px 10px 2px 10px;

border: 1px solid #C0C0C0;

font: normal 10px/12px verdana;

color: #000;

text-align:left;

display: block;}

</style>

</head>

 

<body>

<p>

| <a href="http://www.mikezilla.com">mikezilla.com</a>

</p>

Tooltips using ONLY CSS, no JavaScript: Mike Golding 2002

<p class="link"><a href="http://www.notestips.com">link 1<span>Tooltip1: This link takes you to www.notestips.com - demo</span></a></p>

<p class="link"><a href="http://www.notestips.com">link 2<span>Tooltip2: This link takes you to www.notestips.com - another demo</span></a></p>

<a href="#" OnClick="return false;">No tooltip</a>

<br />

<p class="link"><a href="http://www.notestips.com">link 3<span>Tooltip3: This link takes you to www.notestips.com<br /> This tooltip is on...<br />...multiple lines - yet another demo</span></a></p>

 

 

<br />

&copy <a href="http://www.notestips.com">Mike Golding</a> 2002

<br /><br />

 

</body>

</html>

Some references in a glance





Send email with attachments in SharePoint

SPUtility.SendEmail.. can be used most of the time to send email.
But when you want to send email with attachments..
you can use SmtpClient from System.Net.Mail namespace.

Namespaces required

using System.Net.Mail;
using Microsoft.SharePoint.Administration;

First you need to get a instance to the SMTP server configured in your sharepoint farm

private SmtpClient LoadSmtpInformation()
{
    string smtpServer = SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;
    SmtpClient client = new SmtpClient(smtpServer);
    client.Credentials = new System.Net.NetworkCredential("mmangaldas", "");
    return client;
}


Once you have that, let say you want to send the attachments in a list item as email attachments..

private MailMessage BuildMailMessage(SPListItem item)
{
    MailMessage message = new MailMessage();
    SPList list = item.ParentList;
    
    message.From = new MailAddress(SPAdministrationWebApplication.Local.OutboundMailSenderAddress.ToString());
    message.To.Add(new MailAddress("to@mycompany.com");
    message.IsBodyHtml = true;
    message.Body = "Hi there, check out the attachment";
    message.Subject = "Sent Attachment";
    
    for (int attachmentIndex = 0; attachmentIndex < item.Attachments.Count; attachmentIndex++)
    {
        string url = item.Attachments.UrlPrefix + item.Attachments[attachmentIndex];
        SPFile file = list.ParentWeb.GetFile(url);
        Message.Attachments.Add(new Attachment(file.OpenBinaryStream(), file.Name));
    }

    return message;
}
Finally, use the SMTP instance to send the mail.
client.Send(BuildMailMessage(item));
Complete code for an itemeventreciever sending email with attachments can be downloaded here.

Some Small Information to remember

  1. If your solution specifies elements (a.k.a. "resources") that need to be merged into a Web.config file (i.e. "for a Web application") then you must specify the url parameter. If your solution does not have an assembly or if your solution contains workflows, then you cannot specify the url parameter. more details...
  2. To enable session, do it in the CA and also in the web.config. SSP has to be provisioned. aspnet_regsql must be execute at the end. more details..
  3. Modifying Sharepoint Documents Icon is as simple as changing a value in the xml file... 12\Template\XML\docicon.xml. more info..
  4. To show the standard SharePoint icon against new list items in a data view web part (or other XSLT web parts), use the following snippet:

    <xsl:if test="ddwrt:IfNew(string(@Created))">
        
    <img src="/_layouts/1033/images/new.gif" alt="New" />
    </
    xsl:if>
  5. Reveal Unknown Error on Sharepoint 2007 pages
    <SafeMode ... CallStack="false" ...> and change it to CallStack="true"
    Set <customErrors mode="On" /> to mode="Off"
    Set <compilation batch="false" debug="false"> to <compilation batch="true" debug="true">

Custom Forms for List Menu - New, Edit and Display forms

There are two ways by which this can be done... 1. using VS.Net 2. Sharepoint Designer VS.Net: To create custom forms follow the steps.. a. Create a User Controls which reads fromt he URL Request string values . b. Create a Webpart, and call the UC in the webpart. 3. Deploy the Webpart. 4. Browse to the New Item page of the list item. 5. CLick on Site Actions > Edit Page 6. Hide the existing webpart and insert the newly created webpart. Sharepoint Designer: Follow this link.. http://office.microsoft.com/en-us/sharepointdesigner/HA101191111033.aspx