Wednesday, January 25, 2012

Error occurred in deployment step 'Recycle IIS Application Pool':Cannot connect to the SharePoint site: http://sps01/sites/test/. Make sure that this is a valid URL and the SharePoint site is running on the local computer. If you moved this project to a new computer or if the URL of the SharePoint site has changed since you created the project, update the Site URL property of the project.

Visual studio uses the following process to deploy your solution: vssphost4.exe Open your task manager and find the process in the list; take a note of the User Name under which this process is running, let’s say it’s myadmin_account

Now, open your SQL Management Studio and ensure this Username is added as a DBOWNER to the following databases:

SharePoint_Config
SharePoint_AdminContent_[guid]
SharePoint Site Content DB

sql permissions
Close and Open your Visual Studio again, this will ensure the service is recycled; this should fix above deployment error. If you’re still having same issue, End the process in taskmanager and then re-start VS 2010.



sharepoint send email with attachment

While we working with SMTP in sharepoint projects. It is mandatory to provide SMTP server name to send emails or we can use SPUtility.SendMail().

But it is strongly recommended to use Object model for getting SMTP server name for good coding practice.

Below is the peace of code to do the same :

string smtpServer = SPAdministrationWebApplication.Local.OutboundMailServiceInstance.Server.Address;

string smtpFrom = SPAdministrationWebApplication.Local.OutboundMailSenderAddress;

MailMessage message = new MailMessage(smtpFrom, "test@gmail.com");

message.Subject = "Happy Birthday";

WebClient client = new WebClient();
client.Credentials = CredentialCache.DefaultNetworkCredentials;

string imagePath = web.Url + "/_layouts/images/BirthdayImage.gif";
LinkedResource image1 = new LinkedResource(SPUtility.GetGenericSetupPath("TEMPLATE\\LAYOUTS\\IMAGES\\BirthdayImage.gif"));

image1.ContentId = "birthdayimage";

AlternateView avHtml = AlternateView.CreateAlternateViewFromString("
" + "Have a blast with frineds and family!!! Have a great day!!!", null, MediaTypeNames.Text.Html);

avHtml.LinkedResources.Add(image1);

message.AlternateViews.Add(avHtml);

message.IsBodyHtml = true;

SmtpClient smtpClient = new SmtpClient(smtpServer);
smtpClient.Send(message);



Happy coding !!!