Attaching a document(from sharepoint library) to an email event

  • 20 November 2012
  • 5 replies
  • 16 views

Badge +1

 


 


 


 


 


 


 


 


 


 


 


 


 


 



 



 



 


Hi guys, I am trying to attach a document from a sharepoint document library to an email event message, but all my workflow instances go to an error state :



Could not load file or assembly 'Microsoft.SharePoint.Library, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified.


I have referenced the dll but I am still getting the error, please advice


Thanks in advance.


Please find the server object model code below:


can i use the client object model instead of the server object model ???



try


{



 



 



 


string siteUrl = K2.ProcessInstance.DataFields["MossSiteUrl"

].Value.ToString();



 



 



 


using (SPSite site = new SPSite

(siteUrl))


{



 



 



 


using (SPWeb

web = site.OpenWeb())


{



web.AllowUnsafeUpdates =



 



 


true

;



 



 



 


//ApplicantDocuments



 



 



 


string fileName = K2.ProcessInstance.Folio.Replace("/", "_") + "incompleteinformationletter.pdf"

;



 



 



 


string url = siteUrl + "/" + "ApplicantDocuments" + "/"

+ fileName;



 



 



 


SPFile

file = web.GetFile(url);



 



 



 


//



 



 



 


byte[] buffer = (byte

[])file.OpenBinary();



System.IO.



 



 


MemoryStream ms = new System.IO.MemoryStream

(buffer);



 



 



 


this.EmailMessage.Attachments.Add(new Attachment(ms, "AcknowledgementLetter.pdf"

));



web.AllowUnsafeUpdates =



 



 


false

;


 


}


}


}



 



 



 


catch (Exception

ex)



5 replies

Badge +9


Dumasoka, this is covered with out of the box events. Using K2 Studio you can get this done real quick by doing the following:


 


- Create a new Data field and select Binary as the type


- Using the SharePoint documents event, select Download Documents > To K2 Field, specify the document location in SharePoint and store the result in data field created above


- Now in your email event, specify the data field from above as the attachment


- Done 


Badge +1

Hello Renier,


Thanks for the reply man...


One word for you... SUCCESS!!!!


Many thanks..

Badge +1
Hello Renier,

We are deploying on client site wih the suggested solution...

When configuring the Sharepoint Document event we get the following error when testing the site URL connection :

"The request has failed with HTTP status 404 : Not Found"

Please Help,

Thanks in advance
Badge +1

Hi Renier,


 


I found this poster, I've tried to use your recommendation but i am receiving "server was unable to process request error,  Cannot open file"...


Can you please give more details


 


Thanks

Badge +1

Hi Dumasoka,


 


Can you please explain how did u use this recommendation as its not working for me. i am receiving error "server was unable to process request,  Cannot open file"


 


Thanks

Reply