Copied to clipboard

Flag this post as spam?

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


  • Darryl Godden 145 posts 197 karma points
    May 13, 2010 @ 11:24
    Darryl Godden
    0

    Upload Property for Document Type

    Hi all,

    Quick question, hopefully, I have a document type with an upload property, users will create the content through a form I am writing. With regards to the upload, do I need to create a media type and store the document in that with a link to the media stored in the uplaod property or is there a (better) way to go about this, here's the code I currently have, as you can see the upload code is currently commented out whilst I try and figure out the best way to go about this:

    protected

     

    void btnSave_Click(object sender, EventArgs e)

    {

     

    if (m_ParentNode <= 0)

    {

     

    return;

    }

     

    // Validate

     

    if (!rfvArticle.IsValid || !rfvTitle.IsValid)

    {

     

    return;

    }

     

    // Grab a reference to our News Documnet Type

     

    DocumentType dct = DocumentType.GetByAlias("News Article");

     

    // Validate

     

    if (dct == null)

    {

    lblStatus.Text =

    "Unable to add News Article at this time";

     

    return;

    }

     

    // Create a new document under the news "parent node" -

     

    Document doc = Document.MakeNew(txtTitle.Text, dct, User.GetUser(0), ParentNode);

     

     

    // Populate the data.

    doc.getProperty(

    "newsTitle").Value = txtTitle.Text;

    doc.getProperty(

    "newsDate").Value = DateTime.Now;

    doc.getProperty(

    "newsCopy").Value = txtArticle.Text;

    doc.getProperty(

    "member").Value = umbraco.cms.businesslogic.member.Member.GetCurrentMember().Id;

     

    // Upload the file to the server

     

    //if (fuNewsDocument.HasFile)

     

    //{

     

    // MediaType mt = MediaType.GetByAlias("News Document");

     

    // Media EV = Media.MakeNew(txtTitle.Text, mt, User.GetUser(0), 1784);

     

    // System.IO.Directory.CreateDirectory(Request.PhysicalApplicationPath + "/media/" + EV.Id);

     

    // fuNewsDocument.SaveAs(Request.PhysicalApplicationPath + "/media/" + EV.Id + "/" + fuNewsDocument.FileName);

     

    // umbraco.cms.businesslogic.property.Property newsDocument = EV.getProperty("newsDocument");

     

    // newsDocument.Value = "/media/" + EV.Id + "/" + fuNewsDocument.FileName;

     

    // EV.Save();

     

    // umbraco.library.UpdateDocumentCache(EV.Id);

     

    //}

     

    // Save and Publish

    doc.Publish(

    User.GetUser(0));

    umbraco.

    library.UpdateDocumentCache(doc.Id);

    lblStatus.Text =

    "News item added";

    txtArticle.Visible =

    false;

     

    //txtDate.Visible = false;

    txtTitle.Visible =

    false;

     

    //imgCal.Visible = false;

    btnSave.Visible =

    false;

    }

     

    Thanks.

  • Sebastiaan Janssen 5061 posts 15523 karma points MVP admin hq
    May 13, 2010 @ 12:52
    Sebastiaan Janssen
    1

    The upload field property just stores a string with the path of the file. So you can upload it anywhere you want and then just store the path.

    When someone upload from the admin interface, it will automatically create a folder in media and upload it there, but it's not required.

  • Darryl Godden 145 posts 197 karma points
    May 13, 2010 @ 12:55
    Darryl Godden
    0

    That's great to know, thanks Sebastian.

Please Sign in or register to post replies

Write your reply to:

Draft