I export some data to a csv on an angular/.NET Core app
a ; is missing after the first csv field, while the other ; are there
and the instructions used are the same for the other fields
StringBuilder sb = new StringBuilder();
sb.Append("Id; Civility;Name; Email; Phone;");
sb.Append("\r\n");
for (int i = 0; i < partners.Count; i++)
{
Partner p = partners[i];
sb.Append('"' + p.Id + '"' + ';');
sb.Append('"' +(p.Manager.Civility==0?"Mr":"Mme") +'"'+ ';');
sb.Append('"' + p.Manager.FirstName+" "+ p.Manager.LastName + '"' + ';');
...
here is the part that sends it to the web client for download
DateTime localDate = DateTime.Now;
var date = localDate.ToString("MM_dd_yy_HH_mm_ss");
var filename = "Partners_" + date + ".csv";
Response.Headers.Add("x-file-name", filename);
Response.Headers.Add("Access-Control-Expose-Headers", "x-file-name");
return File(Encoding.UTF8.GetBytes(sb.ToString()), "text/csv", filename);
why is the ; missing in the data ?
apparently the quotes are missing too for the id field
thanks for your time on this
This happens because adding up an int with a char yields an int as result.
var x = 'a' + 5;
//yields 102 as 'a' is implicitly cast from char to int, where 'a' holds the value of 97
You can fix it by either converting the int to a string by using ToString() or you can use strings instead of chars e.g.
sb.Append("\"" + p.Id + "\";"); //the " is escaped using \
Related
I want do below query in Entity Framework
select
cast(p_min as varchar) + '' + cast(p_max as varchar)
from
user_behave_fact
where
beef_dairy_stat = 'True' and param_id = 2
group by
p_min,p_max
go
Since you have not mentioned a language, I am writing code in C#.
Try this:
using (var dbContext = new DatabaseContext())
{
var output = (
from fact in dbContext.user_behave_facts
where fact.beef_dairy_stat == "True" && fact.param_id == 2
group fact by new {fact.p_min, fact.p_max} in grp
select new
{
ColName = grp.Key.p_min.ToString() + " " + grp.Key.p_max.ToString()
}
).ToList();
}
.ToList() can be changed according to your expectations
#set($a = 10)
#set($b = 123)
#set($c = 456)
// If query string "q1" is not available then set $q1,$q2 to default values
#if($!input.params('q1') && $input.params('q1').empty)
#set($q1 = $b)
#set($q2 = $c)
// If query string "q1" available but not "q2" then add some value to $q1 and set it as $q2
#elseif($!input.params('q2') && $input.params('q2').empty)
#set($q1 = $input.params('q1'))
#set($q2 = $a + $q1 )
// If both query strings available then set them
#else
#set($q1 = $input.params('q1'))
#set($q2 = $input.params('q2'))
#end
I'm triying the above code in Integration request body mapping template. In second case where only q1 is specified as some number (let's say 10) then $q2 should be 22( 12 + 10) but it's becoming as 1210, I assume this is because those $q1 and $q2 are strings and they are getting combined.
So I tried to cast them using this answer, but I'm getting internal server error.
How can I cast string to int and them as integers?
The solution given in the other question works for me. Try this (just the second part of if-else):
#set($a = 10)
#set($q1 = $input.params('q1'))
#set($Integer = 0)
#set($q2 = $Integer.parseInt($q1) + $a)
{
"params" : {
"a" : "$a",
"q1" : "$q1",
"q2" : "$q2"
}
}
I have a large PDF that has been combined from multiple documents.
How can I split the PDF back into multiple documents with a keyword delimiter?
As well as Adobe Reader you will need Adobe Acrobat.
Add the following script using the Action Wizard:
Paste in the following script and modify for your needs. See //comments for help on customisation.
/* Extract Pages into Documents by Keyword */
// Iterates over all pages and find a given string and extracts all
// pages on which that string is found to a new file.
var pageArray = [];
var pageArrayEnd = [];
var stringToSearchFor = app.response("This Action Script splits the document by a keyword on each X number of pages, please enter the keyword:");
for (var p = 0; p < this.numPages; p++) {
// iterate over all words
for (var n = 0; n < this.getPageNumWords(p); n++) {
// DEBUGGING HELP, UNCOMMENT NEXT LINE, CHANGE TO MATCH MULTIPLE WORDS OR WHAT EVER ORDER, eg if ((this.getPageNthWord(p, n) == stringToSearchFor) && (this.getPageNthWord(p, n + 1) == stringToSearchForTWO)) {..., Also add a prompt for the second search word and iterate one less for (var n = 0; n < this.getPageNumWords(p) - 1; n++) ...
//app.alert("Word is " + this.getPageNthWord(p, n));
if (this.getPageNthWord(p, n) == stringToSearchFor) {
//app.alert("Found word on page " + p + " word number " + n, 3);
if (pageArray.length > 0) {
pageArrayEnd.push(p - 1);
}
pageArray.push(p);
break;
}
}
}
pageArrayEnd.push(this.numPages - 1);
//app.alert("Number of sub documents " + pageArray.length, 3);
if (pageArray.length > 0) {
// extract all pages that contain the string into a new document
for (var n = 0; n < pageArray.length; n++) {
var d = app.newDoc(); // this will add a blank page - we need to remove that once we are done
//app.alert("New Doc using pages " + pageArray[n] + " to " + pageArrayEnd[n], 3);
d.insertPages( {
nPage: d.numPages-1,
cPath: this.path,
nStart: pageArray[n],
nEnd: pageArrayEnd[n],
} );
// remove the first page
d.deletePages(0);
d.saveAs({ cPath: this.path.replace(".pdf","") + n + ".pdf" });
d.closeDoc(true);
}
}
Please have a look at this guide on how to split PDF into multiple file:
// Used to register all DLL assemblies.
WorkRegistry.Reset();
String inputFilePath = Program.RootPath + "\\" + "1.pdf";
String outputFileName = "Output";
int[] splitIndex = new int[3] { 1, 3, 5 }; // Valid value for each index: 1 to (Page Count - 1).
// Create output PDF file path list
List<String> outputFilePaths = new List<String>();
for (int i = 0; i <= splitIndex.Length; i++)
{
outputFilePaths.Add(Program.RootPath + "\\" + outputFileName + "_" + i.ToString() + ".pdf");
}
// Split input PDF file to 4 files:
// File 0: page 0.
// File 1: page 1 ~ 2.
// File 2: page 3 ~ 4.
// File 3: page 5 ~ the last page.
PDFDocument.SplitDocument(inputFilePath, splitIndex, outputFilePaths.ToArray());
I am new to MVC4 with Entity Framework. Now i am doing RDLC report, here i am passing the parameters to the Report to Filter the data. It's working on local. When i am publishing on server it's not working. It's showing exception like ( An error occurred while processing your request). I am not able to find the exact error. Please help me to resolve this problem. Thanks in advance.
This is my Controller code:
var name = Convert.ToString(form["name"]);
var date = Convert.ToString(form["cdate"]);
var dateList = Convert.ToDateTime(form["cdate"]);
string id = Convert.ToString(form["value"]);
//id = "PDF";
LocalReport lr = new LocalReport();
string path = Path.Combine(Server.MapPath("../Reports"), "DailyReport.rdlc");
if (System.IO.File.Exists(path))
{
lr.ReportPath = path;
}
else
{
return View("Index");
}
//Assigning the parameters to the list
List<ReportParameter> lst = new List<ReportParameter>();
ReportParameter rptName = new ReportParameter("rptname", name);
ReportParameter rptDate = new ReportParameter("rptdate", date);
lst.Add(rptName);
lst.Add(rptDate);
lr.SetParameters(lst);
var rptData =
from d in db.Tbl_DailyReport
where (d.CreatedOn == dateList)
join u in db.Tbl_Users on d.CreatedBy equals u.UserID
where (u.UserName == name)
join c in db.Tbl_Mst_City on u.UserCity equals c.CityId
join ds in db.Tbl_Mst_Designation on u.UserDesignation equals ds.DesignationID
select new
{
u.UserName,
c.CityName,
ds.Designation,
d.DailyReport,
d.Achivement,
d.ReportTime,
d.Comment,
d.CreatedOn
};
//Passing the parameters to the report
ReportDataSource rd = new ReportDataSource("DataSet_dr", rptData);
lr.DataSources.Add(rd);
lr.Refresh();
string reportType = id;
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + id + "</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>0.5in</MarginLeft>" +
" <MarginRight>0.5in</MarginRight>" +
" <MarginBottom>0.5in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = lr.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return File(renderedBytes, mimeType);
Not sure what you want but try setting properties of RDLC report as following while publishing your website.
Build action = Content,
Copy to output Directory = Copy if newer.
and publish your website.
You can read more about publishing RDLC Here
Hello I jsut wondering if its posibble to have a query on web sql cause im using a phonegap for phone development and i have an error on this code
tx.executeSql("SELECT * FROM DEMO WHERE log=(\"?\")", [_searchtext], function (tx, results) {
var len = results.rows.length, i;
msg = "<p>Found rows: " + len + "</p>";
document.querySelector('#status2').innerHTML += msg;
for (i = 0; i < len; i++){
msg = "<p><b>" + results.rows.item(i).log + "</b></p>";
document.querySelector('#status2').innerHTML += msg;
}
}, null);
and I can't have any result but on SELECT * FROM DEMO i have a lot of result.
all I am doing is to get all data and put on the loop and condition the data to the searchtext. but i love to make it on the websql. thanks.