private string
DownloadDocument(ICrmService
crmService, salesliteratureitem
sli)
{
string attachid =
sli.salesliteratureitemid.Value.ToString();
string
objecttypecode = "1070";
//SaleLiteratureItem
string url =
"http://shadowfax:5555"
+
"/Activities/Attachment/download.aspx?AttachmentType=" +
objecttypecode
+ "&AttachmentId=" +
attachid;
System.Net.WebClient
myWebClient = new
System.Net.WebClient();
myWebClient.Credentials = new
System.Net.NetworkCredential("user",
"password",
"computer");
string fname =
Path.Combine(Path.GetTempPath(),
sli.filename);
myWebClient.DownloadFile(url, fname);
return fname;
}
private bool
UploadDocument(ICrmService
crmService, Guid
EmailID, string
filename, string
mimeType, ref
int attachNo)
{
if (!File.Exists(filename))
{ // file must exist
return
false;
}
// load file in
FileInfo pointer =
new
FileInfo(filename);
FileStream
fileStream = pointer.OpenRead();
byte[] byteData =
new
byte[(int)fileStream.Length];
fileStream.Read(byteData, 0, (int)fileStream.Length);
string encodedData =
System.Convert.ToBase64String(byteData);
fileStream.Flush();
fileStream.Close();
FileInfo fli =
new
FileInfo(filename);
// Create the request object to upload the
file to CRM.
activitymimeattachment
upload = new
activitymimeattachment();
upload.activityid = new
Lookup();
upload.activityid.Value = EmailID;
upload.activityid.type = EntityName.email.ToString();
upload.attachmentnumber = new
CrmNumber(++attachNo);
upload.filename = Path.GetFileName(filename);
upload.filesize = new
CrmNumber((int)fli.Length);
upload.mimetype = mimeType;
upload.body = encodedData;
// Upload the file to CRM.
crmService.Create(upload);
return
true;
}