FineUploader CSV标头验证

时间:2016-06-01 19:18:29

标签: csv fine-uploader

我查看过FineUploader文档,想要问社区,以防万一我错过了。需要允许用户上传CSV文件,但希望检查CSV中的标题以确保它们符合要求。这是在FineUploader设置中执行此操作的方法吗?

例如,确保用户上传的CSV具有名字,姓氏,地址,电话的列标题。如果它与那些列标题不匹配,则返回错误消息。谢谢!

1 个答案:

答案 0 :(得分:1)

这种类型的自定义验证完全为什么custom validation回调被添加到Fine Uploader中。在您的情况下,由于您需要访问 using (var file = new StreamWriter("c:\\Test\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".csv")) { file.Write("Com Stat,"); file.Write("Trip Stat,"); file.WriteLine("Voltage"); string ComRead = null; string TripRead = null; string VoltRead = null; CBox1.BackColor = Color.Green; CBox2.BackColor = Color.Green; CBox3.BackColor = Color.Red; CBox4.BackColor = Color.Green; CBox5.BackColor = Color.Green; CBox6.BackColor = Color.Green; CBox7.BackColor = Color.Green; CBox8.BackColor = Color.Red; CBox9.BackColor = Color.Green; CBox10.BackColor = Color.Green; TBox1.BackColor = Color.Red; TBox2.BackColor = Color.Green; TBox3.BackColor = Color.Green; TBox4.BackColor = Color.Green; TBox5.BackColor = Color.Green; TBox6.BackColor = Color.Green; TBox7.BackColor = Color.Green; TBox8.BackColor = Color.Green; TBox9.BackColor = Color.Red; TBox10.BackColor = Color.Green; VBox1.Text = "10.0 V"; VBox2.Text = "5.0 V"; VBox3.Text = "---"; VBox4.Text = "5.0 V"; VBox5.Text = "3.0 V"; VBox6.Text = "5.0 V"; VBox7.Text = "5.0 V"; VBox8.Text = "---"; VBox9.Text = "0.0 V"; VBox10.Text = "5.0 V"; for (int i = 1; i < 11; i++) { foreach (var richBox in this.Controls.OfType<RichTextBox>()) { if ((richBox.Name.StartsWith("CBox" + i)) && (richBox.BackColor == Color.Green)) { ComRead = "True"; } else { ComRead = "False"; } file.Write(ComRead + ","); if ((richBox.Name.StartsWith("TBox" + i)) && (richBox.BackColor == Color.Green)) { TripRead = "True"; } else { TripRead = "False"; } file.Write(TripRead + ","); if (richBox.Name.StartsWith("VBox" + i)) { VoltRead = richBox.Text; } file.WriteLine(VoltRead); } } file.Close(); MessageBox.Show("Demo Complete"); } File,因此您可以提交返回Blob的{​​{3}}。在此回调中,您可以确定该文件是否为CSV。如果是,您可以使用an onSubmit callback读取客户端文件,解析文件以确定它是否符合您的要求。如果是这样,只需履行返回的承诺。否则,拒绝它。请注意,您可以通过FileReader获取对文件ID的基础PromiseFile的访问权限。