locked
Sales Literature file attachment RRS feed

  • Question

  • hello

    Can i add file attachment from code  to sales literature item?
    Is there any way to do it?

    Thanks
    Wednesday, March 5, 2008 3:14 PM

Answers

  • I found the solution!

       Dim fs As IO.FileStream = IO.File.Open(<file path>, IO.FileMode.Open, IO.FileAccess.Read)
                Dim bytes() As Byte = Nothing

                ReDim bytes(fs.Length)
                fs.Read(bytes, 0, fs.Length)

                Dim DocBody As String = System.Convert.ToBase64String(bytes)
                salesliteratureitem.documentbody = DocBody
      salesliteratureitem.filename = "filename.ext"

    To upload or remove an attachment, use the Update method, setting the filename and mimetype properties. This uploads an attachment that has been decoded into a base64 string format. The System.Convert.ToBase64String method can be used to convert the contents of a data file into base64 formatted string. There is a maximum file size limit on the uploaded file data. That limit is defined in the system registry. For more information, see maxuploadfilesizeV4d0_SP5700r_maxrecordsforexporttoexcel.

    http://msdn2.microsoft.com/en-us/library/bb928279.aspx
    Thursday, March 6, 2008 10:02 AM

All replies

  •  

    I dont think so its supported.

     

    Regards,

    Imran

     

    http://microsoftcrm3.blogspot.com

     

    Wednesday, March 5, 2008 4:10 PM
    Moderator
  • Hi.

     

    Yes you can, sales literature entity has a child document entity called salesliteratureitem.

    The class exposes the capabilities to upload or remove an attachment.

     

    Cheers,

    Adi

     

    Wednesday, March 5, 2008 6:11 PM
  • Adi do you know how to do it?

    The salesliteratureitem does not contains any upload or remove attachment.

    The attachment is saved in database in documentbody field and it looks like stream or somethink like that.

    Thanks
    Thursday, March 6, 2008 9:01 AM
  • I found the solution!

       Dim fs As IO.FileStream = IO.File.Open(<file path>, IO.FileMode.Open, IO.FileAccess.Read)
                Dim bytes() As Byte = Nothing

                ReDim bytes(fs.Length)
                fs.Read(bytes, 0, fs.Length)

                Dim DocBody As String = System.Convert.ToBase64String(bytes)
                salesliteratureitem.documentbody = DocBody
      salesliteratureitem.filename = "filename.ext"

    To upload or remove an attachment, use the Update method, setting the filename and mimetype properties. This uploads an attachment that has been decoded into a base64 string format. The System.Convert.ToBase64String method can be used to convert the contents of a data file into base64 formatted string. There is a maximum file size limit on the uploaded file data. That limit is defined in the system registry. For more information, see maxuploadfilesizeV4d0_SP5700r_maxrecordsforexporttoexcel.

    http://msdn2.microsoft.com/en-us/library/bb928279.aspx
    Thursday, March 6, 2008 10:02 AM
  • hi SZCZEPN,

    I am using webservice to code. But i can't get .documentbody method in salesliteratureitem object. Where can i find it???
    Sohaib Ahmad [Business Management Solution Professional] http://www.solutiontalk.blogspot.com
    Sunday, September 20, 2009 4:51 PM
  • Hi, All.

    see it is not listed in  CRM 3.0
    http://msdn.microsoft.com/en-us/library/aa662625.aspx 

    But in CRM 4.0 it is listed.

    http://msdn.microsoft.com/en-us/library/bb929462.aspx 

    Is there is any way besides direct access to database table / view and converting binary from there?


    Which is supported by MS?

    Tuesday, September 22, 2009 6:06 PM