2

I'm using the Quickbase C# SDK to submit a form to Quickbase from an external site. I want to attach a file along with the form and can't seem to figure out how to do so.

Below is a stripped version of my code:

ASPX

<form id="form1" runat="server">
<asp:TextBox ID="txtFileName" CssClass="textbox" Columns="40" runat="server"></asp:TextBox>
<input type="file" id="attachment1" runat="server" />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
</form>

CS

protected void btnSubmit_Click(object sender, EventArgs e)
{
    IQClient client = QuickBase.Login("username", "password", "domain"); 
    IQApplication app = client.Connect("db_id", "app_token";
    AppInfo appInfo = app.GetApplicationInfo();
    IQTable table = app.GetTable("table_id");

    IQRecord newRecord = table.NewRecord();
    newRecord["File Name"] = txtFileName.Text;
    // attach file?
    newRecord.AcceptChanges();
    table.AcceptChanges();
    client.Logout();
}

Thanks in advance.

Raghu
  • 817
  • 1
  • 7
  • 21

1 Answers1

2

Of course I'd figure out my own question after submitting it to StackOverflow. Of course.

But I'll post my solution just in case other people are having the same problem.

I had to add a function to QuickBase C# SDK and recompile the DLL to get this to work.

Add this line to IQRecord.cs:

void UploadFile(string columnName, string filePath);

Add this function to QRecord.cs:

public void UploadFile(string columnName, string filePath)
{
    // create new field with columnName
    var index = GetColumnIndex(columnName);
    CreateNewField(index, columnName);

    // change field type to file
    Columns[index].ColumnType = FieldType.file;

    // Get field location with column index
    var fieldIndex = _fields.IndexOf(new QField(Columns[index].ColumnId));
    SetExistingField(index, fieldIndex, filePath);
}

Compile and use like so:

// code to upload file to temporary location
newRecord.UploadFile("Story", "path_to_temporary_location");
// delete temporary file
  • Thank you so much for this post! I did not need to upload a file, I just needed to know how to add a new record to a Quickbase table, and your post showed me how. – Rani Radcliff Jul 19 '18 at 17:21