我正在使用Quickbase C# SDK从外部站点向Quickbase提交表单。我想将文件与表单一起附加,似乎无法弄清楚该怎么做。

下面是我的代码的剥离版本:

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();
}


提前致谢。

最佳答案

当然,在将其提交给StackOverflow之后,我会想出自己的问题。当然。

但是我会发布我的解决方案,以防其他人遇到相同的问题。

我必须向QuickBase C# SDK添加一个函数并重新编译DLL才能使其正常工作。

将此行添加到IQRecord.cs:

void UploadFile(string columnName, string filePath);


将此函数添加到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);
}


像这样编译和使用:

// code to upload file to temporary location
newRecord.UploadFile("Story", "path_to_temporary_location");
// delete temporary file

关于c# - 如何在C#中使用Quickbase API上传文件?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20846544/

10-10 21:42