amar31282
asked on
how to download annotation attachments from Microsoft dynamics 4.0 Cases
HI All,
I am working on a self service portal as part of extension of the Microsoft Dynamics.
I have a web scenario where I am logging Cases directly in MSD from Web using the Web portal.
I am able to log new case and insert/retreive Notes/Artilces from the Case as part of discussions.
I also have one option to upload the attachements with the Note which is working fine for me.
The Issue comes when i try to download the attachments.
I am able to download only txt files correctly all other formats are always corrupted when i download the file.
Below is the code which i m using to download file
private void DownloadFile(string FileData, String FileName, int FileSize, String MimeType)
{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/x-unknown";
Response.AppendHeader("Con tent-Dispo sition", "attachment; filename=\"" + FileName + "\"");
Response.BinaryWrite(Conve rt.FromBas e64String( FileData)) ;
Response.End();
}
For uploading the file i m using
annotation.documentbody=Co nvert.ToBa se64String (fuAttachm ent.FileBy tes)
Can please anyone help me on the issue that why is the file not downloaded correctly.
One thing more The attachments which are uploaded from web can be downloaded from the MSD Case correctly so there is no issue with uploaded format.
Thanks in Advance..!
I am working on a self service portal as part of extension of the Microsoft Dynamics.
I have a web scenario where I am logging Cases directly in MSD from Web using the Web portal.
I am able to log new case and insert/retreive Notes/Artilces from the Case as part of discussions.
I also have one option to upload the attachements with the Note which is working fine for me.
The Issue comes when i try to download the attachments.
I am able to download only txt files correctly all other formats are always corrupted when i download the file.
Below is the code which i m using to download file
private void DownloadFile(string FileData, String FileName, int FileSize, String MimeType)
{
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/x-unknown";
Response.AppendHeader("Con
Response.BinaryWrite(Conve
Response.End();
}
For uploading the file i m using
annotation.documentbody=Co
Can please anyone help me on the issue that why is the file not downloaded correctly.
One thing more The attachments which are uploaded from web can be downloaded from the MSD Case correctly so there is no issue with uploaded format.
Thanks in Advance..!
ASKER
HI Chinmay,
Thanks for reply.
I have already tried this but its also giving same issue. The file saved by filestream is working fine for Text file but all other pdf/word/image are always corrupted..
Also i need to download the file by clicking on a button so i want it through Response..
Regards,
Amarjit
Thanks for reply.
I have already tried this but its also giving same issue. The file saved by filestream is working fine for Text file but all other pdf/word/image are always corrupted..
Also i need to download the file by clicking on a button so i want it through Response..
Regards,
Amarjit
Hi Amarjit,
Well you can always get it downloaded on server and then do a response.redirect to the file.
Ok for the files which are not working properly.. can you do one thing? Open that file in a notepad and tell me what you see. Do you see binary data or something else?
Regards,
Chinmay
Well you can always get it downloaded on server and then do a response.redirect to the file.
Ok for the files which are not working properly.. can you do one thing? Open that file in a notepad and tell me what you see. Do you see binary data or something else?
Regards,
Chinmay
ASKER
HI Chinmay
yes i can download them but i was simply not intrested in saving them :)
anyways in what ever way it works i will be fine with that..
I have off today from office and will be there on monday so i can't assure the file text 100% right now but as far as i remember it is in binary format.
also one thing When i download the Image the image is opened but it have just the upper left corner printed correctly rest all is always blank....
Regards,
Amarjit
yes i can download them but i was simply not intrested in saving them :)
anyways in what ever way it works i will be fine with that..
I have off today from office and will be there on monday so i can't assure the file text 100% right now but as far as i remember it is in binary format.
also one thing When i download the Image the image is opened but it have just the upper left corner printed correctly rest all is always blank....
Regards,
Amarjit
Hi Amarjit,
Now I am very curious, I will check this out in my environment as soon as I get some free time.
Regards,
Chinmay
Now I am very curious, I will check this out in my environment as soon as I get some free time.
Regards,
Chinmay
ASKER
ok sure and thanks for your effords.. I appreciate it. :).
I am not sure how CRM stores the attachements when we save it from CRM but I am saving it using
annotation.documentbody=Co nvert.ToBa se64String (fuAttachm ent.FileBy tes)
and it is opening fine in CRM ... so not sure what i am missing and its not opening in a web browser.
one question In my browser i am having all the Browser history and rest everything in No Save mode so my browser doesn't ever remember anything (and i have not checked the attachments on any other system yet ). Is there any minimum possibility that it could be the reason for corrupted file or incomplete jpg
Regards,
Amarjit
I am not sure how CRM stores the attachements when we save it from CRM but I am saving it using
annotation.documentbody=Co
and it is opening fine in CRM ... so not sure what i am missing and its not opening in a web browser.
one question In my browser i am having all the Browser history and rest everything in No Save mode so my browser doesn't ever remember anything (and i have not checked the attachments on any other system yet ). Is there any minimum possibility that it could be the reason for corrupted file or incomplete jpg
Regards,
Amarjit
Really Don't know. It won't take me long to figure it out once I check it in my environment so don't worry. At most I think some kind of minor disposition or encoding issue. And if it is not than it will be interesting to figure it out.
Regards,
Chinmay
Regards,
Chinmay
ASKER
Nice.. to hear
I will be waiting Impatiently
Regard,
Amarjit
I will be waiting Impatiently
Regard,
Amarjit
Your last message pushed me to do this right now rather than later so here is the result, with the code I've sent there was an error
you are supposed to use byte[] fileContent = Convert.FromBase64String(a nnotationA ttachment. documentbo dy);
I did this with a WinForms application so you still might face some issues with directly writing file to response.
First confirm that this is working fine or not and then we will see why it is giving you issues with Response.Write. I doubt that FileData is culprit but let's see how it goes later on.
Regards,
Chinmay
you are supposed to use byte[] fileContent = Convert.FromBase64String(a
I did this with a WinForms application so you still might face some issues with directly writing file to response.
First confirm that this is working fine or not and then we will see why it is giving you issues with Response.Write. I doubt that FileData is culprit but let's see how it goes later on.
Regards,
Chinmay
ASKER
hmm not really following you
i m using DownloadFile(annotationAtt achment.do cumentbody , annotationAttachment.FileN ame, annotationAttachment.FileS ize, annotationAttachment.mimet ype)
To call the download function so i think the same way as u said..
Hmm I am really frustrated that i can't test it right now as i am not at office today and will be there on monday only..
did u find some luck to download other format correctly with this code ..?
i m using DownloadFile(annotationAtt
To call the download function so i think the same way as u said..
Hmm I am really frustrated that i can't test it right now as i am not at office today and will be there on monday only..
did u find some luck to download other format correctly with this code ..?
Of course.. I did it with a PNG and a simple text file, you want me to try other formats?
ASKER
can u paste your code here
ASKER
Please try with pdf also
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hmm i have really tried the same code yesterday but it never worked fine for me
Strange...
Seems like now i need to check on another browser seems like my browser settings are causing this issue..
Anyways i thanks a lot for you help I will close the question now as i have seen that i m not doing anything wrong in my code.
I will post here if it worked fine for me on another browser or open new question if it still didn't work..:)
Thanks a lot for all your help and time...
Regards,
Amarjit
Strange...
Seems like now i need to check on another browser seems like my browser settings are causing this issue..
Anyways i thanks a lot for you help I will close the question now as i have seen that i m not doing anything wrong in my code.
I will post here if it worked fine for me on another browser or open new question if it still didn't work..:)
Thanks a lot for all your help and time...
Regards,
Amarjit
ASKER
thanks a lot.
You are welcome.. and thanks for closing this question... I am kind of.. just 2K points away from my next title in Experts-Exchange. :)
ASKER
haha yes i have seen that i read your blog .. By the way i m also an expert on EE but not getting enough time to spend here.
Ya.. I quit my job and kind of spending time as I see it fit.. EE is not priority as I've got lot of other things to do but sometimes out of curiosity I give priority to EE questions. :)
ASKER
Hey Chinmay,
Today Once again i tried to download the annotation attachments using the code given by you.
// Download the attachment in the current execution folder.
using (FileStream fileStream = new FileStream(annotationAttac
hment.filename, FileMode.OpenOrCreate))
{
byte[] fileContent = Convert.FromBase64String(a nnotationA ttachment. documentbo dy);
fileStream.Write(fileConte nt, 0, fileContent.Length);
}
But it was still not working for me... I scrubbed my head a lot and finally found two issues
Guess what..?
1. I was passing the annotaion.documentbody to downloadfile method as string and string length was not able to handle so long data so it was truncated.
----after solving issue 1
2. I was using CRM SDK for retrieving the attachements and again the SDK's annotation.documentBody length was not enough to handle whole data so it was again truncated.
So finally i used the Web referenced service and got it working lol...
Regards,
Amarjit
Today Once again i tried to download the annotation attachments using the code given by you.
// Download the attachment in the current execution folder.
using (FileStream fileStream = new FileStream(annotationAttac
hment.filename, FileMode.OpenOrCreate))
{
byte[] fileContent = Convert.FromBase64String(a
fileStream.Write(fileConte
}
But it was still not working for me... I scrubbed my head a lot and finally found two issues
Guess what..?
1. I was passing the annotaion.documentbody to downloadfile method as string and string length was not able to handle so long data so it was truncated.
----after solving issue 1
2. I was using CRM SDK for retrieving the attachements and again the SDK's annotation.documentBody length was not enough to handle whole data so it was again truncated.
So finally i used the Web referenced service and got it working lol...
Regards,
Amarjit
Hi Amarjit,
:)... funny... see I asked you.. try downloading to your local folder first than response.redirect but ya this SDK issues new to me... I will give it a shot if I get some free time. And Thanks for the tip :)
Regards,
Chinmay
:)... funny... see I asked you.. try downloading to your local folder first than response.redirect but ya this SDK issues new to me... I will give it a shot if I get some free time. And Thanks for the tip :)
Regards,
Chinmay
ASKER
Hey chinmay
one more strange thing
see this link
http://allfaq.org/forums/t/178615.aspx
i found it today when i was searching for my solution
one more strange thing
see this link
http://allfaq.org/forums/t/178615.aspx
i found it today when i was searching for my solution
WTF!!! A Site RIP Dude... Report this to EE... You do it in a minute or I will... that's my bloody code.. n your bloody question... These Rascals.. are taking it away... GRRR GRRRR DO something please... report to EE please.
ASKER
i have already done dear.. :)
Kewl... Thanks. :)
Try the following code snippet
#region How to download attachment from annotation record
// SDK: annotationId = new Guid("{bee08735-09d3-de11-
Guid annotationId = setupAnnotationId;
// Define the columns to retrieve from the annotation record.
ColumnSet cols1 = new ColumnSet();
cols1.Attributes = new string[] { "filename", "documentbody" };
// Retrieve the annotation record.
annotation annotationAttachment = (annotation)service.Retrie
// Download the attachment in the current execution folder.
using (FileStream fileStream = new FileStream(annotationAttac
{
byte[] fileContent = new UTF8Encoding(true).GetByte
fileStream.Write(fileConte
}
#endregion
Code source : http://msdn.microsoft.com/en-us/library/cc151179.aspx
Regards,
Chinmay