Copied to clipboard

Flag this post as spam?

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


  • Adam Prendergast 33 posts 77 karma points c-trib
    Aug 02, 2012 @ 13:04
    Adam Prendergast
    0

    Programmatically inserting a File Upload into a Contour entries table - RecordField

    Hi there,

    The way we have recently been working with Contour is to have a bespoke form (fluentValidation/Unit testing reasons) that hooks into Contour and saves the records by generating a RecordField from fromo values.

    private void GenerateRecordField(Record record, Field field, object value)
    {
    Guid key = Guid.NewGuid();
    RecordField recordField = new RecordField()
    {
    Field = field,
    Key = key,
    Record = record.Id,
    Values = new List<object>() { value }
    };
    var recordFieldStorage = new RecordFieldStorage();
    recordFieldStorage.InsertRecordField(recordField);
    record.RecordFields.Add(key, recordField);
    }

     

    This has worked brilliantly for text fields but how do I prepare a file upload for Contour.

    I have tried passing the HtmlInputFile to the RecordField Value list<object>.

    Is there a different type other than RecordField that is needed?

    Thanks.

  • Comment author was deleted

    Aug 02, 2012 @ 15:15

    Passing a htmlInputFile won't work you'll just need to pass it the path to the file as a string

    So you'll have to handle the upload in your own code for the time being since the upload is happening in the upload control

    if (fu != null && fu.UploadControl.HasFile)
                    {
                        _value.Clear();
                        
                        string dir = Configuration.Path + "/files/" + this.AssociatedField.Form.ToString() + "/" + Guid.NewGuid().ToString() + "/";
    
                        if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath(dir)))
                            System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath(dir));
    
                        fu.UploadControl.SaveAs(HttpContext.Current.Server.MapPath(dir + SafeUrl(fu.UploadControl.FileName)));
    
                        _value.Add(dir + SafeUrl(fu.UploadControl.FileName));
                    }
Please Sign in or register to post replies

Write your reply to:

Draft