Copied to clipboard

Flag this post as spam?

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


  • Matthias Bier 30 posts 90 karma points
    Jan 18, 2013 @ 16:38
    Matthias Bier
    0

    Contour 3 (Razor), Custom FieldType (FileUpload)

    Hi,

    I want to write a custom FieldType for Contour that acts a FileUpload control with some filters to restrict uploading to certain file types.

    I tried to implement it following the example on http://www.nibble.be/?p=154 but I don't see how I can process (save) the uploaded file and store the file path in the record. The example is a simple textbox that seems to need no processing at all to store the value. But for my fileupload this does not work. I also tried to override the "function public override List<object> Values" but it did not work at all...

    I saw that the developer docs are not yet updated so I wonder if it's possible to have the source code for the built in file upload FieldType. I guess this would help me to understand how to implement my own FieldType.

    Thank you

    Matthias


  • Comment author was deleted

    Jan 20, 2013 @ 15:06

    Hi Matthias,

    You'll need to do the saving in the ProcessValue method that you can overwrite

    Here is the code from the default upload 


    public override List<object> ProcessValue(HttpContextBase httpContext) { List<Object> vals = new List<object>(); //files bool filesaved = false; var files = httpContext.Request.Files; if (files.Count > 0 && files.AllKeys.Contains(this.AssociatedField.Id.ToString())) { HttpPostedFileBase file = null; file = files[this.AssociatedField.Id.ToString()]; if (file.ContentLength > 0) { string dir = Configuration.Path + "/files/" + Guid.NewGuid().ToString() + "/"; if (!System.IO.Directory.Exists(httpContext.Server.MapPath(dir))) System.IO.Directory.CreateDirectory(httpContext.Server.MapPath(dir)); file.SaveAs(httpContext.Server.MapPath(dir + file.FileName)); vals.Add(dir + file.FileName); filesaved = true; } } if (!filesaved) { vals.Add(httpContext.Request[this.AssociatedField.Id.ToString() + "_file"] ?? ""); } return vals; }
  • Matthias Bier 30 posts 90 karma points
    Jan 29, 2013 @ 15:33
    Matthias Bier
    0

    Hi Tim,

    Thank you for the code. I will try this.

    Matthias 

Please Sign in or register to post replies

Write your reply to:

Draft