help needed creating csv-data from contour records in razor
Let me start by saying that I am NOT an experienced programmer. So my code and my understanding of some of these issues will surely suffer from that fact :)
Here is my situation:
I'm stuck in a project where my job is to provide contour records in CSV format for use in a windows software job-graduate program.
I have come so far that I've written a razor script that is used when the client through an administration page, choose some form entries to export and click a button. The script captures the IDs of the records to be exported and then retrieve them using The Contour API.
Then I generate some unique IDs for each record (used to sort the fields so they appear in the same order as they appear in the form). Then i (try to) set the output to be a file and write the new output to the client, who then can download and import the file into his job-candidate program.
When I download a test export file and import its data into Microsoft Excel using the import data from textfile it works fine, but when the developer of the job candidate program use their import function to create an import feature in the program, they say to me that they can not import the data, and they believe that there are errors in the format.
One of my problems is probably that I do not know enough about format and encoding requirements and problem areas relating to csv format.
So it is my hope that one of you skilled developers can look at my code and help me with some advice.
@* IF WE HAVE RECORD ID DATA - START *@ if(!string.IsNullOrEmpty(@Request["records"])){
string[] records = @Request["records"].Split(new Char[]{','});
var recordStorage2 = new RecordStorage(); var formStorage2 = new FormStorage(); Record rec2 = recordStorage2.GetRecord(new Guid(@records[0])); Form form2 = formStorage2.GetForm(rec2.Form);
@* FOREACH RECORD - START *@ foreach(string record in @records){
var recordStorage = new RecordStorage();
Record rec = recordStorage.GetRecord(new Guid(@record));
@* FOREACH RECORDFIELD IN RECORD - START *@ foreach(RecordField field in rec.RecordFields.Values){
@* BUILDING A UNIQ ID TO USE FOR SORTING COLUMNS *@ string idBeta = @field.Field.PageIndex < 10 ? "0" + @field.Field.PageIndex.ToString() : @field.Field.PageIndex.ToString(); idBeta += @field.Field.FieldsetIndex < 10 ? "0" + @field.Field.FieldsetIndex.ToString() : @field.Field.FieldsetIndex.ToString(); idBeta += @field.Field.SortOrder < 10 ? "0" + @field.Field.SortOrder.ToString() : @field.Field.SortOrder.ToString(); idBeta += " " + @Html.Raw(@field.Field.Caption);
@* IF THE COLLECTION OF DATA ROWS ALREADY HAS A ROW WITH THE ID OF THE CURRENT ID *@ if(fieldSortOrderBeta.ContainsKey(idBeta) == true) { fieldSortOrderBeta[idBeta].Add(@field.ValuesAsString()); }
@* IF THE COLLECTION OF DATA ROWS DOES NOT HAVE A ROW WITH THE ID OF THE CURRENT ID *@ if(fieldSortOrderBeta.ContainsKey(idBeta) == false) { List<string> dic = new List<string>(); dic.Add(@field.ValuesAsString());
fieldSortOrderBeta.Add(idBeta, dic); }
}@* FOREACH RECORDFIELD IN RECORD - END *@
}@* FOREACH RECORD - END *@
}@* IF WE HAVE RECORD ID DATA - END*@ }
@* START PRINTING OUR DATA *@ @{
var list = @fieldSortOrderBeta.Keys.ToList(); list.Sort();
yes, i know that it is possible to export to csv from the recordviewer. But because the two formulars have so many fields (about 200 for the one and about 300 for the other form ) the formviewer can't load entries into the recordviewer. And if i use the icon in the top of the interface, i can't select single records, but get all of them.
But i would like to continue to use the extra admin-interface functions that i am creating, because it gives me the option to select single records, and also to delete records.
Do you have any comments/suggestions to my posted code? And maybe you can spot any errors that i am making?
help needed creating csv-data from contour records in razor
Let me start by saying that I am NOT an experienced programmer. So my code and my understanding of some of these issues will surely suffer from that fact :)
Here is my situation:
I'm stuck in a project where my job is to provide contour records in CSV format for use in a windows software job-graduate program.
I have come so far that I've written a razor script that is used when the client through an administration page, choose some form entries to export and click a button. The script captures the IDs of the records to be exported and then retrieve them using The Contour API.
Then I generate some unique IDs for each record (used to sort the fields so they appear in the same order as they appear in the form). Then i (try to) set the output to be a file and write the new output to the client, who then can download and import the file into his job-candidate program.
When I download a test export file and import its data into Microsoft Excel using the import data from textfile it works fine, but when the developer of the job candidate program use their import function to create an import feature in the program, they say to me that they can not import the data, and they believe that there are errors in the format.
One of my problems is probably that I do not know enough about format and encoding requirements and problem areas relating to csv format.
So it is my hope that one of you skilled developers can look at my code and help me with some advice.
And here is my code:
Comment author was deleted
You do know that it's possible to export to csv format from within the records viewer right? Or isn't that an option in your case?
Hi Tim,
yes, i know that it is possible to export to csv from the recordviewer. But because the two formulars have so many fields (about 200 for the one and about 300 for the other form ) the formviewer can't load entries into the recordviewer. And if i use the icon in the top of the interface, i can't select single records, but get all of them.
But i would like to continue to use the extra admin-interface functions that i am creating, because it gives me the option to select single records, and also to delete records.
Do you have any comments/suggestions to my posted code? And maybe you can spot any errors that i am making?
Hi Christian, were you able to resolve this? I'm dealing with a similar issue.
Hi Amir.
No, i did not manage to use the contour backend in Umbraco to export data
is working on a reply...