Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Graeme 19 posts 111 karma points
    Apr 29, 2014 @ 18:20
    Graeme
    0

    saving a file to media section

    Hi,

    I have a pdf that I have created in a user control, (using PDF Sharp). I'm attempting to now save this pdf within the media section. I can get the pdf into a filestream, just not sure how I now save it into the umbracoFile property.

    I have something like this at the moment:

                // get the parent id for the container folder

                var parentId =  GetParentFolder();

     

                // create a new media file for the pdf

                var mediaType = MediaType.GetByAlias("File");

                var mediaFile = Media.MakeNew("My new file", mediaType, new User(0), parentId);

     

                // set the PdfDoc as the umbracoFile

                // save the image into a mem stream location

                var fileStream = new MemoryStream();

                PdfDoc.Save(fileStream, false);

                mediaFile.getProperty("umbracoFile").Value = fileStream;

                fileStream.Close();

                mediaFile.Save();

     

    Any pointers would be greatly appreciated.

     

     

Please Sign in or register to post replies

Write your reply to:

Draft