Wednesday, September 17, 2014

Tuesday, September 16, 2014

Specified value is not supported for the urlOfFile parameter

This error is misleading, actually we should not use SPFolder.Files collection to retrieve SPFile object the correct way is to use SPWeb.GetFile method.

Reference:
http://www.sharepointnadeem.com/2012/01/urloffile-parameter-name-specified.html

Thursday, September 11, 2014

Rename sharepoint server

Renaming a sharepiont server can get you in serious trouble unless you follow very careful approach. This blog has very useful information which has helped our team resolve the issue that central admin site was unavailable after renaming SP 2010 server

http://blog.walisystemsinc.com/2012/08/how-to-change-sharepoint-2010-server.html

Run miisactivate.exe

This post explains how to fix this error in sharepoint 2010 environment

http://blog.helloitsliam.com/Lists/Posts/Post.aspx?ID=7

Wednesday, September 10, 2014

Email with Embedded (Inline) image in sharepoint

In asp.net we can send an email with inline image as explained in this post
http://stackoverflow.com/questions/18358534/send-inline-image-in-email

But in sharepoint the procedure is slightly different. I have used below post to do the stuff

http://sharepoint-tamizha.blogspot.co.uk/2013/08/send-email-with-embedded-images-in-c.html


And the final code looks like


byte[] imgByte = null;
SPFile file = SPContext.Current.Web.GetFile(ImageUrl);
                                            imgByte = file.OpenBinary();

// Creating Unique ID for adding image referrence
string GUId1 = Guid.NewGuid().ToString();               

// frame the HTML with the img tag and above unique id
string htmlBody = "<html><body><div><img src=\"cid:" + GUId1 + "\"></div></body></html>";

// Create alternateview object with Mime type HTML
AlternateView avHtml = AlternateView.CreateAlternateViewFromString
                    (htmlBody, nullMediaTypeNames.Text.Html);

//Create object for Linked Resource with the Image physical path or Image Stream
MemoryStream stream = new MemoryStream(imgByte);
                LinkedResource pic1 = new LinkedResource(stream, "image/png");

// Provide the previously created Unique ID to associate the Image with the respective img src.
pic1.ContentId = GUId1;

//Add the Linked Resource to the AlternateView
avHtml.LinkedResources.Add(pic1);

string from = SPContext.Current.Web.Site.WebApplication.OutboundMailSenderAddress;

string smtpAddress =SPContext.Current.Web.Site.WebApplication.OutboundMailServiceInstance.Server.Address;

// Assign SMTP address
SmtpClient smtpClient = new SmtpClient();
smtpClient.Host = smtpAddress;

MailMessage mailMessage = new MailMessage(from, toRecipients);
mailMessage.Subject = subject;

// Add the Alternate view with the Mail message
mailMessage.AlternateViews.Add(avHtml);
mailMessage.IsBodyHtml = true;


smtpClient.Send(mailMessage);

Monday, September 8, 2014

Scheduled reminders in Sharepoint 2007

While surfing through google search results I found this great utility created by Mullivan for sp 2007,

http://www.codeproject.com/Articles/32753/Send-scheduled-Reminder-Alerts-by-email-in-SharePo

I can be easily modified to work for SP 2010 and it has a lot of features.


Regex Email validation in c# dot net core

 Use this regex /^_?[a-zA-Z0-9]([a-zA-Z0-9]*[._+-])*[a-zA-Z0-9_]+@(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.(?!-)[A-Za-z0-9-]{1,63}(?<!-))*\.[A-...