Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

save attachment for jpg against contact on folder on pre create event

$
0
0

i attach code for reference  problem that when  i try to save the attachment gave and file is not uploaded  .

need urgent help  thanks in advance...

public void Execute(IServiceProvider serviceProvider)
{


#region Service Context
// Get the execution context from the service provider...
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

// Get the organization service reference...
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
//Extract the tracing service for use in debugging.
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
//svcContext = new svcCRMContext(service);
#endregion

try
{
// Verify that the target entity represents an note.
if (context.InputParameters.Contains("Target") && (context.InputParameters["Target"] is Entity))
{
Entity entity = (Entity)context.InputParameters["Target"];
if (context.PrimaryEntityName == "annotation")
{


string filename = entity.Attributes["filename"].ToString();
byte[] Image = DecodeFrom64(entity.Attributes["documentbody"].ToString());
// Guid regarding = (Guid) entity.Attributes["objectid"];
string Subject = entity.Attributes["subject"].ToString();
// Guid owner = (Guid)entity.Attributes["owninguser"];

//Entity annotation = new Entity("annotation");
//annotation["Subject"] = entity.Attributes["Subject"];
//annotation["DocumentBody"] = entity.Attributes["DocumentBody"];
//annotation["FileName"] = entity.Attributes["FileName"].ToString();
////if (context.OutputParameters.Contains("id"))
////{
//// Guid objectid = new Guid(context.OutputParameters["id"].ToString());
//// string ObjectidTypeCode = "eo_localdata";
////}
////annotation["ObjectId"] = entity.Attributes["objectid"].ToString();
//annotation["owninguser"] = (Guid)entity.Attributes["owninguser"];
//annotation["createdon"] = (Guid)entity.Attributes["createdo"];
//annotation["FileSize"] = entity.Attributes["FileSize"].ToString();
//service.Create(annotation);
_fileExt = Path.GetExtension(filename);
byte[] _Image = Image;

_EventId = entity.Id;
if (_fileExt == ".jpg" || _fileExt == ".png")
{
InsertImages(_EventId, Image, _fileExt);
}

}

}

}
catch (FaultException<OrganizationServiceFault> ex)
{
throw new InvalidPluginExecutionException("An error occurred in the FollupupPlugin plug-in.", ex);
}
catch (Exception ex)
{
tracingService.Trace("FollowupPlugin: {0}", ex.ToString());
throw;
}


}

internal static byte[] DecodeFrom64(string p)
{
//byte[] encodedDataAsBytes = System.Convert.FromBase64String(p);
byte[] encodedDataAsBytes = Encoding.ASCII.GetBytes(p);

return encodedDataAsBytes;
}


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images