Dynamically changing CSV data source using ApplyLogOnInfo - crystal-reports

I have a .rpt file that I have created by setting it's data source as a text (csv) file using the (Access/Excel (DAO) ) option.
Now I want the same .rpt file loaded using a C# code and each time my C# code will change the input file and I want a new report to be generated based on the data in the new text file.
I am doing the following code and when I export the file to a pdf document, it still displays the data according to the data in the old input file.
I have checked off the option in the .rpt file that says "save data with report" and "verify on first refresh".
What am I missing here?
CODE:
cryRpt = new ReportDocument();
cryRpt.Load(reportfile);
Tables tables = cryRpt.Database.Tables;
TableLogOnInfo tableLogonInfo;
foreach (Table table in cryRpt.Database.Tables)
{
tableLogonInfo = table.LogOnInfo;
tableLogonInfo.TableName = "MYdata_BS_NEW#csv";
table.Location = "MYdata_BS_NEW#csv";
table.ApplyLogOnInfo(tableLogonInfo);
}
cryRpt.Refresh();
// After this I export the report to pdf document.

Related

How to read from excel and write into excel in Protractor?

I have integrated with Rally which downloads test cases .Every Test case has its own test data in excel spread sheet form.
I am planning to consolidate all test cases excel data into single excel sheet and read the test data from this consolidated excel as part of data driven testing.
So I would like to know how to read from excel and write into excel in protractor.
Hope i am clear .
Thank you.
You can use one of these node packages.
https://www.npmjs.com/package/xlsx
https://www.npmjs.com/package/edit-xlsx
I think the second one would be ideal for you as you need to edit existing excel files.
I'm using Exceljs to make my test cases data driven.
https://www.npmjs.com/package/exceljs
Code sample for reading from excel:
var Excel = require('exceljs');
var wrkbook = new Excel.Workbook();
wrkbook.xlsx.readFile('Auto.xlsx').then(function() {
var worksheet = wrkbook.getWorksheet('Master');
worksheet.eachRow(function (Row, rowNumber) {
console.log("Row " + rowNumber + " = " + JSON.stringify(Row.values));
});
});

How to add filepath and filename attribute to the Activitymimeattachment entity in CRM?

I am a newbie to CRM. Trying to create an email with an attachment. Got the email creation part working but facing a hard time in attaching the file that I want to attach from the file explorer.
The activitymimeattachment entity has an attribute called "filename" but that attaches an empty file with the given name rather than the file from file explorer. Tried giving the full path of the file in the filename attribute but that attach only the file with the given name, but not from the explorer.
This is the code I have to attach a file to the email.
Entity attach = new Entity("activitymimeattachment");
attach["filename"] = "Stack.txt";
attach["mimetype"] = "text/plain";
attach["attachmentnumber"] = 1;
attach["objectid"] = new EntityReference("email", emailId);
attach["objecttypecode"] = "email";
service.Create(attach);
Stack.txt file is in my C:/users/name/Files/Stack.txt
How do I specify the file path to the activitymimeattachment attribute?
Any answer to the question would be much helpful.
Thanks in advance.
You need to read in the text and base64 encode it to the body attribute:
attach["body"] = System.Convert.ToBase64String(new ASCIIEncoding().GetBytes(System.IO.File.ReadAllText(#"C:\Temp\alljobs.txt")));

Google Apps Script: Export Dashboard to CSV

I've created a Dashboard similar to the example provided on the Google Apps Script Help Center. It contains controls which filters the spreadsheet that contains the data. I would like to add an option on the dashboard that would allow the users to export the filtered view to a new CSV file or Google Sheets file that would be saved in their Drive however I've no idea how to do this. Any suggestions?
Here's a code snippet from Google tutorial:
function saveAsCSV() {
// Prompts the user for the file name
var fileName = Browser.inputBox("Save CSV file as (e.g. myCSVFile):");
// Check that the file name entered wasn't empty
if (fileName.length !== 0) {
// Add the ".csv" extension to the file name
fileName = fileName + ".csv";
// Convert the range data to CSV format
var csvFile = convertRangeToCsvFile_(fileName);
// Create a file in the Docs List with the given name and the CSV data
DocsList.createFile(fileName, csvFile);
}
else {
Browser.msgBox("Error: Please enter a CSV file name.");
}
}*
View the full tutorial and code here.

error in generating pdf using iTextSharp means previous pdf file is diplayed

I am working in asp .net mvc3.
I have these statements in controller class:
PdfWriter.GetInstance(doc, new FileStream((Request.PhysicalApplicationPath + "\\Receipt5.pdf"),
FileMode.Create));
doc.Open();
PdfPTable table = new PdfPTable(2);
table.AddCell("tt[0]");
table.AddCell("tt[1]");
doc.close();
All time my values are changing but in pdf sometimes showing old result. please tell me what should i do for it that whenever i press done button then new pdf document should generate.
i am using iTextSharp to generate pdf.
It seems that you're not able to replace the old file cause it is locked.
Try to delete it and see what happens.
Anyway, consider that if more than one user tries to print the same document you can have a concurrency problem.
I would suggest you to use a generated file name:
var newFile = System.IO.Path.Combine(Request.PhysicalApplicationPath, Guid.NewGuid().ToString() + ".pdf");

excel to xml conversion using ado

How to convert excel data into xml file using ado.net?
You can use the Microsoft Jet OLEDB 4.0 Data Provider to read the Excel file. Information about how to establish a connection to an Excel file can be found here.
This article explains how to read an Excel file using the provider. Once you have read the data, you can compose your XML document using LINQ to XML or the System.Xml classes.
In Excel, you can save the file to XML by using the File menu and changing the saved file type to XML spreadsheet.
If you want to read an Excel XML file with ADO.Net, try the XmlReader.
Or see this step-by-step example from Microsoft.
I've not used ado.net, but I've used xquery very successfully for this. Use excel export to create an XML file, then write xquery/xpath commands to convert as you want. Excel XML export format is pretty gnarly but it does do the job. Use the Oxygen 30 day eval license to lighten the xquery debug job.
use this code :
public static DataSet exceldata(string filelocation)
{
DataSet ds = new DataSet();
OleDbCommand excelCommand = new OleDbCommand();OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();
string excelConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + filelocation + "; Extended Properties =Excel 8.0;";
OleDbConnection excelConn = new OleDbConnection(excelConnStr);
excelConn.Open();
DataTable dtPatterns = new DataTable();excelCommand = new OleDbCommand("SELECT UUID, `PATTERN` as PATTERN, `PLAN` as PLAN FROM [PATTERNS$]", excelConn);
excelDataAdapter.SelectCommand = excelCommand;
excelDataAdapter.Fill(dtPatterns);
dtPatterns.TableName = "Patterns";
ds.Tables.Add(dtPatterns);
return ds;
}
and then convert returned datatable to xml with DataTable.WriteXml()