Copied to clipboard

Flag this post as spam?

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


  • Jesper Hauge 298 posts 486 karma points c-trib
    Feb 08, 2010 @ 17:15
    Jesper Hauge
    0

    Create document attached file

    I'm doing a custom import of old data from a old umbraco site, and for that reason I need to create some nodes from code.

    I've got creation of documents and setting of ordinary properties nailed, but I don't know how to go about population properties of datatype upload. How do you go about this?

    Regards
    Jesper Hauge

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Feb 08, 2010 @ 17:22
    Dirk De Grave
    0

    Jesper,

    I don't know syntax by heart, but would suggest to do following:

    create a upload datatype on a test document, upload some file, and have a look at the generated xml in the umbraco.config (when published of course). i'm sure you'll need to first create a media item, and fill upload datatype's value for the document with an xml snippet that represents the media node.

     

    Does that make sense?

     

    Cheers,

    /Dirk

  • Richard Soeteman 3875 posts 12037 karma points MVP
    Feb 08, 2010 @ 18:30
    Richard Soeteman
    2

    Hi Jesper,

    Your import comes a few months too early. This functionality is top prio for UmbImport 1.1. I've build this myself for a client (I don't have the source anymore) and what I did was downloading the Umbraco Source code and reverse engineered the Upload Datatype. It's kinda difficult because its generatiing thumbnails, creating folders etc.

    Cheers,

    Richard

  • Jesper Hauge 298 posts 486 karma points c-trib
    Feb 09, 2010 @ 11:02
    Jesper Hauge
    0

    Hi Richard

    I was afraid that it wasn't easy (since it wasn't already in the umbimport package) - was looking into figuring out how to do it by going through the source code. But it looks like a long haul to get there :(

    Thanks for your reply.

    Cheers
    Jesper

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 09, 2010 @ 11:58
    Thomas Höhler
    0

    It depends of how to save the file. Should it be available in the media lib or is it a pure upload field. In the second case you only have to upload the file into the correct folder and populate the filepath to the property value:

    var newDoc = Document.MakeNew("MyNewDocument", new DocumentType(1234), new User(0), 5678);
    var fileUploadProperty = newDoc.getProperty("MYPROPERTYALIAS");
    var mediaId = fileUploadProperty.Id;
    var folder = Server.MapPath(string.Format("/media/{0}", mediaId));
    if (!Directory.Exists(folder))
    Directory.CreateDirectory(folder);
    //SAVE THE FILE TO THE FOLDER...
    string targetFilename = string.Format("/media/{0}/{1}", mediaId, YOURFILENAME);
    string targetFilepath = Server.MapPath(targetFilename);
    fileUploadProperty.Value = targetFilepath;
    newDoc.Publish(new User(0));
    umbraco.library.UpdateDocumentCache(newDoc.Id);

    hth, Thomas

  • Jesper Hauge 298 posts 486 karma points c-trib
    Feb 09, 2010 @ 15:40
    Jesper Hauge
    0

    Thanks Thomas - that sounds great I will try it out!

    Do you have personal experience doing something like this?

    Regards
    Jesper Hauge

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Feb 09, 2010 @ 16:27
    Thomas Höhler
    0

    yes, I have implemented such things for our intranet and on some other private projects. In our intranet and extranet I have implemented some windows forms clients which are connecting via webservices to the umbraco installations uploading files like press releases, things that the users have to do once a day and where the users are tired to login into the umbraco backend. Do you need a hand?

    Thomas

  • Jesper Hauge 298 posts 486 karma points c-trib
    Feb 09, 2010 @ 20:25
    Jesper Hauge
    0

    Hi again

    Thanks a lot. I've done a couple of test runs now, and it looks promising.

    The data is there without the thumbnail, which isn't a big problem. Now I just need to put some finishing touches on the code to handle inconsistencies in the source data, before I can get it up and running.

    Thanks again.

    Cheers
    Jesper Hauge

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies