Feb 15
24
There is a very common business requirement where you need to send an email alert to customers after a particular number of days but only on business days. Business days means only Monday through Friday in most countries. It’s a bit tricky but can be accomplished with ease by following the example given below.
Requirements:
The user gets an alert after 21 days stating that his action is needed on something, say for example a credit card bill payment before it becomes over due.
Logic:
This is simple: Add 21 days from the date in which he made a payment and check whether today is the 21st day.
If “Yes” fire an alert, else do nothing.
DateTime dueDate = actualPaymentMadeDate.AddDays(21); DateTime todayDateTime = DateTime.Now; if (dueDate == todayDateTime ) { Console.WriteLine("It is past 21 days"); } else { Console.WriteLine("It is still not 21 days"); }
Now the second part is that you need to temporarily disable his card if he does not make a payment after 21 days. However, this alert should be sent only on the 3rd business day after 21 days.
Logic:
If the difference is greater than 21 days, then add 21 days to the date in which the payment was made, then find out which day does this date fall under, i.e the day of the date when 21 days are added to the date in which the credit card payment was made. Then write a case statement which would add “n” number of days based on which day the 21st date is like the one shown below. Now for example if the day is Monday then 3 days are added to get the next 3rd business day and if today is that day, then an alert is sent by the timer job.
else if (differenceInDays > 22) { //add 21 days to the date in which the card was issues. DateTime addedPaymentDate = actualPaymentDate.AddDays(21); DateTime finalBusinessday; //find out the day of this date. string currentDay = addedPaymentDate.DayOfWeek.ToString(); //write a case if the day belongs to one of the cases, then what happens, //like monday = add 3 days, tuesday add 3 days, wednesday 5 days, string caseSwitch = currentDay; switch (caseSwitch) { case "Monday": finalBusinessday = addedPaymentDate.AddDays(3); Console.WriteLine("Monday"); break; case "Tuesday": finalBusinessday = addedPaymentDate.AddDays(3); Console.WriteLine("Tuesday"); break; case "Wednesday": finalBusinessday = addedPaymentDate.AddDays(5); Console.WriteLine("Wednesday"); break; case "Thursday": finalBusinessday = addedPaymentDate.AddDays(5); Console.WriteLine("Thursday"); break; case "Friday": finalBusinessday = addedPaymentDate.AddDays(5); Console.WriteLine("Friday"); break; case "Saturday": finalBusinessday = addedPaymentDate.AddDays(4); Console.WriteLine("Saturday"); break; default: finalBusinessday = addedCardIssueDate.AddDays(3); Console.WriteLine("Sunday"); break; } //get to find out the date after adding the days. //if today is == to the obtained date in the previous step send email var dateoffinalBusinessday = finalBusinessday.ToShortDateString(); string dateOftoday = todayDateTime.ToShortDateString(); if (dateoffinalBusinessday == dateOftoday) { DynamicAlerter(1, tcardHolderEmail, tcardNumber, DateTime.Now.ToString(), siteObj); } }
please see screenshots below:
Open Visual Studio 2010 and select New, Project… from the file menu
Select an empty SharePoint project and name it accordingly.
Once the project is created, then add a .cs file to it. Ensure that your cs file is named accordingly like
CompanyName_ModuleName_Urgent_Timer and inherits from SPJobDefinition class.
Method explanations:
The Execute(Guid targetInstanceId) method calls the main method which is UrgentAction_SuspensionAlert(currentTCardList, site) with the list and the site as input parameters.
The UrgentAction_SuspensionAlert(SPList eventsListObj, SPSite siteObj) method takes the list, and site objects as input parameters and does the actual logic of finding
1: If the payment has crossed 21 days then is the 21st day today: then email is fired
2: If the payment has crossed 21 days then find the 3rd business day after the 21st day and if that day is today: fire an email alert to the user
The DynamicAlerter(int stage, string cardHolderEmail,
string accountNumber, string deadlineDate, SPSite site) gets the following as input parameters
stage : is it trying to go for an email alert in the first case > 21 days due payment
or the second case : 3rd business day
Account number : Credit card account number
dead line date : the date in which the payment should have been made
site: spsite object
The string[] BodyTemplateEmail(SPList list,
string retrievalquery) takes in list and CAML query input values and returns a string array that will contain the dynamic email body from a configurable list
The CardAudiListtEmailSave(SPWeb emlwebObj, subject, string bodyContent,
string recipient) take input parameters like subject, the replaced dynamic body content and the credit card holder email ID and saves all this data for audit purposes into a SharePoint list for future reference.
Below is the full code section.
namespace CompanyName_ModuleName_Urgent_Timer { public class CompanyName_ModuleName_Urgent_Timer : SPJobDefinition { #region constant declaration public const string ISSUEDON = "IssuedOn"; public const string CARDHOLDEREMAIL = "CardholderEmail"; public const string CARDHOLDERNAME = "Title"; public const string CARDNUMBER = "CardNumber"; public const string CARDDEADLINEDATE = "DueAmountOnTermination"; public const string JobName = "CompanyName_ModuleName_Urgent_Timer"; public const int sitecollectionIndexPosition = 3; public const string listName = "Credit Card Data"; #endregion public CompanyName_ModuleName_Urgent_Timer() : base() { } public CompanyName_ModuleName_Urgent_Timer(SPWebApplication webApp) : base(JobName, webApp, null, SPJobLockType.Job) { Title = JobName; } /// <summary> /// The main execute method that calls the method urgent actions timer /// </summary> /// <param name="targetInstanceId"></param> public override void Execute(Guid targetInstanceId) { try { // Execute the timer job logic. SPWebApplication webApp = this.Parent as SPWebApplication; SPSite site = webApp.Sites[sitecollectionIndexPosition]; using (SPWeb web = site.OpenWeb()) { SPList currentList = web.Lists[listName]; UrgentAction_SuspensionAlert(currentList, site); } } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory ("Urgent Actions Timer job Failure", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "Failed in sending email alerts for more than 21 day pending jobs: " + ex.Message, ex.StackTrace); } } /// <summary> /// This method finds the difference between the date issues and current date /// then sends the appropriate email alert. If it is greater than 21 days urgent action email is sent /// if it is greater than 22 days, the suspension email is sent /// </summary> /// <param name="eventsListObj"></param> /// <param name="siteObj"></param> private static void UrgentAction_SuspensionAlert(SPList eventsListObj, SPSite siteObj) { try { foreach (SPListItem eventListItem in eventsListObj.Items) { DateTime todayDateTime = DateTime.Now; if (eventListItem[ISSUEDON] != null) { string cardissuanceDate = eventListItem[ISSUEDON].ToString(); string cardNumber = eventListItem[CARDNUMBER].ToString(); string cardDeadlineDate = eventListItem[TCARDDEADLINEDATE].ToString(); string cardHolderEmail = eventListItem[CARDHOLDEREMAIL].ToString(); DateTime actualCardIssueDate = Convert.ToDateTime(cardissuanceDate); string itemUrl = eventListItem.ParentList.ParentWeb.Site.MakeFullUrl (eventListItem.ParentList.DefaultDisplayFormUrl + "?ID=" + eventListItem.ID); TimeSpan timeDifference; if (todayDateTime > actualCardIssueDate) { timeDifference = todayDateTime - actualCardIssueDate; } else { timeDifference = actualCardIssueDate - todayDateTime; } double differenceInDays = timeDifference.TotalDays; if ((differenceInDays > 21) && (differenceInDays < 22)) { DateTime addedCardIssueDateMain = actualCardIssueDate.AddDays(21); DynamicAlerter(0, tcardHolderEmail, tcardNumber, addedCardIssueDateMain.ToString(), siteObj); } else if (differenceInDays > 22) { //add 21 days to the date in which the card was issues. DateTime addedCardIssueDate = actualCardIssueDate.AddDays(21); DateTime finalBusinessday; //find out the day of this date. string currentDay = addedCardIssueDate.DayOfWeek.ToString(); //write a case if the day belongs to one of the cases, then what happens, //like monday = add 3 days, tuesday add 3 days, wednesday 5 days, string caseSwitch = currentDay; switch (caseSwitch) { case "Monday": finalBusinessday = addedCardIssueDate.AddDays(3); Console.WriteLine("Monday"); break; case "Tuesday": finalBusinessday = addedCardIssueDate.AddDays(3); Console.WriteLine("Tuesday"); break; case "Wednesday": finalBusinessday = addedCardIssueDate.AddDays(5); Console.WriteLine("Wednesday"); break; case "Thursday": finalBusinessday = addedCardIssueDate.AddDays(5); Console.WriteLine("Thursday"); break; case "Friday": finalBusinessday = addedCardIssueDate.AddDays(5); Console.WriteLine("Friday"); break; case "Saturday": finalBusinessday = addedCardIssueDate.AddDays(4); Console.WriteLine("Saturday"); break; default: finalBusinessday = addedCardIssueDate.AddDays(3); Console.WriteLine("Sunday"); break; } //get to find out the date after adding the days. //if today is == to the obtained date in the previous step send email var dateoffinalBusinessday = finalBusinessday.ToShortDateString(); string dateOftoday = todayDateTime.ToShortDateString(); if (dateoffinalBusinessday == dateOftoday) { DynamicAlerter(1, tcardHolderEmail, tcardNumber, DateTime.Now.ToString(), siteObj); } } } } } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory ("Credit Card Timer job Failure", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "Failed in finding the difference of days logic: " + ex.Message, ex.StackTrace); } } /// <summary> /// This method is for using a Dynamic Replaceable Email Body for the alerts sent & content retrieval method /// </summary> /// <param name="properties"></param> /// <param name="stage"></param> private static void DynamicAlerter(int stage, string cardHolderEmail, string accountNumber, string deadlineDate, SPSite site) { try { DateTime today = DateTime.Now; DateTime deadline = today.AddDays(21); string[] emailProperties = new string[2]; using (SPWeb web = site.OpenWeb()) { string formattedValue = string.Empty; SPList list = web.Lists["CardEmailBodyTemplates"]; if (stage == 0) { emailProperties = BodyTemplateEmail(list, "URGENT - ACTION REQUIRED"); emailProperties[0] = emailProperties[0].Replace("{cardNumber}", accountNumber); emailProperties[1] = emailProperties[1].Replace("{carddeadline}", deadline.ToString()); } else { emailProperties = BodyTemplateEmail(list, "URGENT - TRAVEL CARD SUSPENSION"); emailProperties[0] = emailProperties[0].Replace("{cardNumber}", accountNumber); emailProperties[1] = emailProperties[1].Replace("{carddeadline}", deadline.ToString()); } SPUtility.SendEmail(web, true, false, cardHolderEmail, emailProperties[0], emailProperties[1]); CardAudiListtEmailSave(web, emailProperties[0], emailProperties[1], cardHolderEmail); } } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("Send Email", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "Error in DynamicAlerter Method" + "for Card item event receivers: " + ex.Message, ex.StackTrace); } } /// <summary> /// Dynamic email Template body builder method /// </summary> /// <param name="list"></param> /// <param name="retrievalquery"></param> /// <param name="stage"></param> /// <returns></returns> private static string[] BodyTemplateEmail(SPList list, string retrievalquery) { string[] dynamicEmailValues = new string[2]; SPQuery query = new SPQuery(); query.RowLimit = 10; query.Query = "<Where><Eq><FieldRef Name='Title' />" + "<Value Type='Text'>" + retrievalquery + "</Value></Eq></Where>"; SPListItemCollection spItemColl = list.GetItems(query); if (spItemColl.Count > 0) { foreach (SPListItem item in spItemColl) { dynamicEmailValues[0] = item["EmailSubject"].ToString(); dynamicEmailValues[1] = item["EmailMessageBody"].ToString(); } } return dynamicEmailValues; } /// <summary> /// This method writes to the Card audit list the details of the every email sent /// </summary> /// <param name="emlwebObj"></param> /// <param name="subject"></param> /// <param name="bodyContent"></param> /// <param name="recipient"></param> private static void CardAudiListtEmailSave(SPWeb emlwebObj, string subject, string bodyContent, string recipient) { try { SPList listObj = emlwebObj.Lists["Card Audit"]; SPListItem itemObj = listObj.Items.Add(); itemObj["Title"] = subject; itemObj["From"] = "CreditCardAlerts@guru.com"; itemObj["To"] = recipient; itemObj["DateSent"] = DateTime.Now; itemObj["MessageBody"] = bodyContent; itemObj.Update(); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("List Timer job Failure", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, "Failed in writing the email details to cardaudit list for past due date payments :" + ex.Message, ex.StackTrace); } } } }
I hope this scenario has been helpful.
Happy coding!
Guru V
If you have encountered an Access Denied message in SharePoint although you have proper permissions to the site, page, list, or library, then it could be one of several reasons. Hopefully one of these several fixes will work for you.
For the site or sub-site with the Publishing feature enabled, ensure all users have read access to the master page library.
Site Actions > Site Settings > Master pages and page layouts > Library tab > Library Permissions > Grant Permissions button. Add Authenticated Users with Read permission level as in the screenshot below.
If you experience Access Denied on file upload or download, it may be your anti-virus settings.
The following folders may have to be excluded from antivirus scanning when you use file-level antivirus software in SharePoint. If these folders are not excluded, you may see unexpected behavior. For example, you may receive “access denied” error messages when files are uploaded.
Reference Links:
http://support.microsoft.com/kb/952167
http://www.symantec.com/business/support/index?page=content&id=TECH141492
Thanks to Ripon Kundu for contributing to this section.
You may also experience an Access Denied while uploading a file to a site that utilizes the Content Organizer feature *and* the site’s Drop Off Library has unique permissions.
“The resolution is to make sure that users have Contribute access to a site’s Drop Off Library” per this article.
This solution, you may notice, bears a strong resemblance to Fix #1. The takeaway here is to really mind your permissions.
Sometimes we are tasked with weird requirements and we go halfway around the world to get them done. Remember one thing: there is quite often a simple shortcut available. I have realized that JavaScript and JQuery are so powerful that they can make these shortcuts achievable for us in an amazingly small amount of time.
Our requirements were simple. They wanted a SharePoint list that has numerous checkboxes on the new item form and they wanted all the boxes to be selected on form load by default. The clients would then de-select a few based on what they wanted.
SharePoint allows only one check box to be selected by default on form load. To achieve our goal, I wrote one single line of code that did the trick… eager to know how? What are we waiting for… Lets dive!!!!
Step 1: Go to your list and add a choice control, as shown below
Step 2: Provide options as shown below and observe that only one option can be selected as default. SharePoint does not allow you or give you the power to select multiple options by default on load in the choice menu although it still give you multi-select option manually.
Step 3: Go back to the list and click on the new item and you would see the newform.aspx opened with only the first option that you selected to be checked by default on form load.
step 4: Open notepad and put the following code into it and save this file with whatever name you want to on your desktop. Remember it should be a text file. In my case I named it multicheckerjqueryfile.txt for an example’s sake as shown below
<script src="http://ServerName/sites/SiteName/SiteAssets/jquery-1.10.2.min.js"></script> <script src="http://ServerName/sites/SiteName/SiteAssets/jquery.SPServices-0.7.2.min.js"></script> <script src="http://ServerName/sites/SiteName/SiteAssets/jquery.SPServices-0.7.2.js"></script> <script type="text/javascript"> $(document).ready(function() { //Get the current user $("INPUT[type='checkbox']").attr('checked',true); }); </script>
Logically what we are doing is getting the choice control through its html disguise and setting it “checked” property attribute to TRUE.
step 5: Now upload this file to your site assets library as shown below along with the three other supportive jquery library files. You can also download the latest version of these files from the internet. For the rest of you who want it quickly, please pick it from our site. P.S: these are not the latest but ones sufficient enough to get you through this task.
I have added these files that I used during my development. You can also download the latest files from the following site (http://jquery.com/download/)
Step 6: Once all the upload is done, type the url of the list and append the newform.aspx with it with some additional parameters. Once done, you should see the new form.aspx page, in editable state as shown below.
So your url should be like
http://servername:port number/Lists/list name/newform.aspx?PageView=Shared&ToolPaneView=2
Step 7: Click on the “Add a Webpart” link and add a content editor web part. In the “Content Link” field, provide the location where you uploaded the text file that contains the logic. in my case it was
http://servername/siteassets/multicheckerjquery.txt as shown below
Step 8: Click on the Apply button and then the OK button. Now refresh the page and you will see all the check boxes checked by default when the page is opened as shown below.
Happy Coding
Guru !!!
On list forms, SharePoint offers a lot of fields Out-of-the-Box plus you are free to create your own custom fields to accommodate requirements and customer data types.
Among the OOTB fields is the hyperlink field which requires either http or https. Sometimes you want a link to a file somewhere (such as a shared drive) for which there is a UNC path but no http path. We will use JQuery to convince SharePoint to accept UNC path names in the hyperlink field. Lets jump into the topic right away.
Step 1: Add a new hyperlink column to your list. Name the hyperlink field as “testhyperlinkfield” or name it whatever you are comfortable with.
Step 2: Download the necessary supportive Jquery library files from the internet and upload them to your Site Assets folder.
I have addded the files that i had used during my development. You can also download the latest files from the following site (http://jquery.com/download/)
Step 3: Open notepad and add the below lines of code and save the file as “hyperlinkrootchanger.txt”
<script src="http://ServerName/sites/SiteName/SiteAssets/jquery-1.10.2.min.js"></script> <script src="http://ServerName/sites/SiteName/SiteAssets/jquery.SPServices-0.7.2.min.js"></script> <script src="http://ServerName/sites/SiteName/SiteAssets/jquery.SPServices-0.7.2.js"></script> <script type="text/javascript"> $(document).ready(function() { $("INPUT[title='testhyperlinkfield']").val('file://'); }); </script>
P.S. Remember to change servername and urls according to your server details
Step 4: Now upload this text file to your SiteAssets library. Copy the url of the location where the file is saved.
Step 5: Now navigate to your list and type the following in the url bar.http://Server Name/Lists/List Name/newform.aspx?PageView=Shared&ToolPaneView=2 the page that opens will enable you to add a web part. Add a content editor web part to this page. Now edit this webpart’s properties where in the “Content Link” property give the location of where you saved the java script text file initially in the site assets library. once this is done, click on Apply and Ok button. Now open the newform.aspx or try to open a new list item page and you should see the changes like shown below:Happy Jquery scripting !!
Guru
Sep 14
8
A user posted a List View Web Part on their intranet site alongside their Announcements (also a List View Web Part). For a cleaner look, I was asked if we could get rid of the column headers for all of the web parts on the page. They aren’t really useful, they state the obvious, and they take up valuable real estate on the site. So let’s get rid of them.
*** Click the images to view them full-size ***
It took a little while via Google to find the solution which was:
A.) not selected as an answer, and
B.) all the way at the bottom.
So I’ll make it quick and easy for you.
<style> .ms-viewheadertr { display: none;} </style>
Success! Now all of the List View web parts on the page will render without the unnecessary column headers.
If you have seen either of the above messages while trying to open a document in SharePoint, you are probably as confused as we were. My user was getting this even though the file was not checked out. Worse still, the message said that the file was locked out… by him. He didn’t have it open and there were no “orphaned” processes of Winword.exe running in Task Manager. So how could this be?
When I Googled this error, I came upon a ridiculously weak thread on TechNet that basically says it’s designed that way and that you have to wait for 10 minutes for the lock to clear. Nonsense!
The culprit in our case was Credential Manager, which may be accessed via Control Panel. Simply select the entry for the web application URL in Credential Manager and delete it by selecting “remove from vault“.
For step-by-step instructions on how to do this (including screenshots), follow the post Step 2: Clear Your Cache in Credential Manager from a few months back.
First, an introduction to the Productivity Hub for SharePoint 2010:
Microsoft has developed the Productivity Hub to help support your ongoing end user training efforts.
The Hub is a SharePoint Server site collection that serves as a learning community and is fully customizable. It provides a central place for your training efforts, and includes training content from Microsoft’s core products.
The Problem
On the main page there is a nifty Slider Silverlight Web Part that allows users to scroll through preview thumbnails of the various videos available. It’s very cool. There’s also a slider on the Videos page. We had the problem recently where the slider on the Videos page was not rendering the preview thumbnails, as seen in the screenshot below.
Clicking the failing-to-load image did correctly launch the appropriate video so that functionality was fine – it was simply that the thumbnails were not showing. They are located in Site Assets / Video Thumbnails folder.
You can find the files listed below. They are named in such a way that it is easy to identify which file is used as a thumbnail for which video.
Video Thumb-Excel.jpg
Video Thumb-InfoPath.jpg
Video Thumb-OneNote.jpg
Video Thumb-Outlook.jpg
Video Thumb-PowerPoint.jpg
Video Thumb-Word.jpg
For these files to not show there are two possible scenarios:
those files are either missing -or- they are corrupt.
In our case they were corrupt. We came to this conclusion because we were not able to download these image files. ( It was throwing a download error stating that the file was corrupt).
The Solution
How these files became corrupt is a mystery. As you might be aware SharePoint does not give the user the privilege to edit image files directly, so we’ll just have to replace them.
First, we have to go get the image files. Open the following site in your browser http://www.spsdemo.com/sites/productivity/. Get the images from here.
Then, simply upload and overwrite the corrupt images -or- delete the old corrupt images from the library and then replace them with the good ones.
Either way: problem solved.
What would it be like if you had power in your hands but still were not able to use it… Yes it happens almost every day in the lives of us SharePoint People. Today we are going to talk about one such situation: the people picker control. You cannot set a default value for the people picker control from the SharePoint UI… wonder why? With a little help from JQuery, we can.
So we are going to make this happen. Lets Start. Create a custom list and add new columns of your choice. One of them should be a people picker control. Here I have given the title of the people picker control to be “Assigned To“. Now there are two ways to implement this functionality. Either open the Newform.aspx in SharePoint Designer, (not a very recommended approach but if you want a quicky, then do this by writing JavaScript and JQuery anywhere below the Content PlaceHolderMain) else open the Newform.aspx page in the browser and insert a content editor web part. Now create a text file and write the JavaScript and JQuery inside this text file, save it as .txt file and upload this to some location in the SharePoint site where you want this functionality to be implemented.
In the content link property of the content editor web part, provide the URL of the location of the text file that we previously created. Please find the code below for this file. These three files need to be loaded onto the server where this code is getting called. ( Please download them from the internet.)
Please find the code below written in JQuery/Javascript. This is the code that needs to be placed for achieving the functionality:
<
<script src="http://yourserver/sites/ListBreak/SiteAssets/jquery-1.10.2.min.js"></script> <script src="http://yourserver/sites/ListBreak/SiteAssets/jquery.SPServices-0.7.2.min.js"></script> <script src="http://yourserver/sites/ListBreak/SiteAssets/jquery.SPServices-0.7.2.js"></script> <script type="text/javascript"> $(document).ready(function(){ //Get the current user var user= $().SPServices.SPGetCurrentUser(); // This is for getting current user var defaultuser = "Guru ,Venkataraman"; // this is for assigning any default user to the control //Set all sharepoint 2010 people picker default to current user $("div[title='People Picker']").text(defaultuser); }); </script>;
Once this is added in the appropriate place with the supportive .js files, you should see the below screen for the newform.aspx on your list with the people picker control populated with a default username.
HAPPY CODING!!! 🙂
Guru
Today we are going to talk about a piece of functionality that would make you feel….Oh i have to have it!. I am talking about the “Email a Link” functionality for an individual list item.
You may think this is already available so what’s the commotion all about? Yes!! This functionality is available in SharePoint document libraries but not for lists. Furthermore, you cannot add this OOTB or as a feature or add-on. It’s just not available. No idea why Microsoft did such a thing. The fundamental principal behind the solution presented here is to exploit the OOTB control that is provided for libraries to a custom list using a little tweak.
This custom Email a Link functionality is implemented for custom lists to have the ability to send a link of that item in an Email client. The use of the ribbon, the power of the JavaScript call to window.open, and the mailto parameters makes the magic come together.
Still confusing? Let’s dive in to the well to find out more.
So let’s start getting our hands dirty by starting with our Visual Studio Custom Ribbon Project. Select your Visual Studio tool to be run as Administrator. Select New project from File menu. You will land in the screen as shown below.
Select an empty SharePoint project. Currently I use C# as my preferred language of instruction.
When you click on the OK button, VS takes you to the config screen as shown below where you select this solution to be a farm solution. We are doing this because this can be globally reused at any site collection.
Click on the Finish button and you should have a SharePoint project created. Please use the name of the project as per your requirement. Now once added, right click on the project and select add new item. In the below screen that is seen, select empty element. Name it appropriately, this is more of an .xml file that is going to do the trick for us.
Open the empty xml file and paste the following code given below: modify a few parameters to suit your requirement.
<br /> <Elements xmlns="http://schemas.microsoft.com/sharepoint/"><br /> <CustomAction<br /> Description="EFH Email A Link"<br /> Title="EFH Email A Link"<br /> Id="{DB6F9FD7-2E67-44a2-9E7D-BE071FBEF309}"<br /> Location="CommandUI.Ribbon"<br /> RegistrationId="100"<br /> RegistrationType="List"<br /> Sequence="1"</strong></em><br /> Rights="ViewListItems"<br /> xmlns="http://schemas.microsoft.com/sharepoint/"><br /> <CommandUIExtensionxmlns="http://schemas.microsoft.com/sharepoint/"><br /> <!-- Define the (UI) button to be used for this custom action --><br /> <CommandUIDefinitions><br /> <CommandUIDefinitionLocation="Ribbon.ListForm.Display.Manage.Controls._children"><br /> <ButtonId="{B4D644C1-B0DE-4856-9F6A-380B47C05D15}"<br /> Command="{AAA6F08B-F53E-4799-BA2F-8D89F0E7AC01}"<br /> Image16by16="/_layouts/1033/images/formatmap16x16.png"<br /> Image16by16Top="-16"<br /> Image16by16Left="-88"<br /> Sequence="1"<br /> LabelText="EFH Email A Link"<br /> Description="EFH Email A Link"<br /> TemplateAlias="o2" /><br /> </CommandUIDefinition><br /> </CommandUIDefinitions><br /> <CommandUIHandlers><br /> <!-- Define the action expected on the button click --><br /> <CommandUIHandlerCommand="{AAA6F08B-F53E-4799-BA2F-8D89F0E7AC01}"<br /> CommandAction="javascript:CustomEmailaLink('{ItemId}','{SiteUrl}','{ItemUrl}');<br /> function <strong><em>CustomEmailaLink</em></strong>(ItemId,SiteUrl,ItemUrl)<br /> var linkValue = encodeURIComponent(window.location.href);<br /> var items = SP.ListOperation.Selection.getSelectedItems();<br /> window.open('mailto:?subject=This Item Needs your attention'+'&amp;body='+ linkValue);<br /> }"/><br /> </CommandUIHandlers><br /> </CommandUIExtension><br /> </CustomAction><br /> </Elements><br />
You screen should look like this
Now for a little explanation :
The main tag would be the <CustomAction which would have
Description=”EFH Email A Link” == Refering to what your ribbon control is all about
Title=”EFH Email A Link” == the title of the ribbon control
Id=”{DB6F9FD7-2E67-44a2-9309}” == unique guid, generated byGUID tool in VS
RegistrationType=”List” == for what type of component would this be used.we specify this explicitely as list
<CommandUIDefinitionLocation=
“Ribbon.ListForm.Display.Manage.Controls._children”>
this is the control inherited from which this ribbon button already exists ( remember i said we need to exploit the existing button from the library email a link functionality.
Image16by16=”/_layouts/1033/images/formatmap16x16.png”
Let this remain as it is as we are using the existing image. in case you want a different image, please create a 16 X 16 pixel sized image and put it into the layouts / 1033 / images location
Image16by16Top=”-16″ = = this attribute would not be valid if you are using a custom image
Image16by16Left=”-88″ = = this attribute would not be valid if you are using a custom image
LabelText=”EFH Email A Link” == the text that would be displayed
this is the main section where we have given our own custom JavaScript function.
CommandAction=”javascript:CustomEmailaLink(‘{ItemId}’,'{SiteUrl}’,'{ItemUrl}’);
function CustomEmailaLink(ItemId,SiteUrl,ItemUrl) {
var linkValue = encodeURIComponent(window.location.href);
var items = SP.ListOperation.Selection.getSelectedItems();
window.open(‘mailto:?subject=This Item Needs your attention’+’&body=’+ linkValue);
What this function does is that it takes in three input parameters like the ID of the individual list item, the url of the site and the url of the individual item and sends it as parameters to the mailto inbuilt function java script function.
Now finally : Run the build, and deploy the solution. Activate the feature and you should be able to see the ribbon control for the library where this function was meant to be as shown below.
“Email a Link ribbon button
This ribbon button invokes the default email client and pre-loads the current item link to the body of the email. If a default email client is not available, then it prompts the user to configure a default email client.
Happy Coding 🙂 !!!!!!!!!
Guru
Several of my users have encountered the problem of three failed login attempts to SharePoint resulting in a blank white screen. This can happen when a user’s login credentials (username and password) are incorrect. Unfortunately, this can also happen when they put in their correct information. This second scenario can be bedeviling so I’ll go over the various tasks you can perform to resolve this problem:
1. Clear your browser cache and restart your browser
2. Clear your cache in Credential Manager
3. Alternate way to clear your cached credentials
4. Add site to Trusted Sites
5. Pass along current credentials to IE
**Please also note the addendum regarding prompts for a mapped drive to a SharePoint site.
Perhaps the easiest and most well known, you’ve probably already tried this step. If you have not, Google the steps and perform them, then restart IE.
Alternatively, if you have WinXP you will not have Credential Manager – you will have Stored Usernames and Passwords instead. This site will guide you on how to clear this system cache in WinXP.
Source: Windows IT Pro website
Internet Explorer lets you categorize websites into different zones with different security policies for each zone. Be default, sites are all categorized as Internet. We will look at two different types of site: Intranet and Trusted Site.
If you are on a company Intranet site you should add the url to your list of sites in your Intranet zone.
If you are experiencing trouble authenticating to an Internet site that you regularly visit (and that you trust) you should add it to your Trusted Sites zone.
You’ll want to configure Internet Explorer for automatic logon with current user name and password as above. However, you’ll also need to edit your registry to tell Windows to allow the webclient service to remember passwords.
Source: http://tipsyouforgot.blogspot.com/2010/06/remember-password-setting-not-working.html
You cannot copy content of this page