Configuration rootWebConfig = WebConfigurationManager.OpenWebConfiguration("/WebSite3");
My project name is WebSite3, however when i try running the code, i get the relative virtual path "WebSite3"is not allowed here.
Try:
Configuration rootWebConfig = WebConfigurationManager.OpenWebConfiguration("~");
That should open to the root of your web application.
This is the code I used to test:
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "";
System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
System.Configuration.KeyValueConfigurationCollection appSettings =
rootWebConfig.AppSettings.Settings;
foreach (string key in appSettings.AllKeys)
{
Label1.Text += "Name: " + key + " Value: " + appSettings[key].Value + "<br />" ;
}
}
Which resulted in the following text on my label (Sensitive info blacked out)
Related
I am using CronicleQueue and I have only one writer/reader. Wanted to cleanup as soon as the reader is done with a CQ4 file. The following code wasn't able to remove the file, is the file reference still held by CQ during onReleased() event?
public class ChronicleFactory {
public SingleChronicleQueue createChronicle(String instance, String persistenceDir, RollCycles rollCycles) {
SingleChronicleQueue chronicle = null;
String thisInstance = instance;
try {
chronicle = SingleChronicleQueueBuilder.binary(persistenceDir).rollCycle(rollCycles).storeFileListener(new StoreFileListener() {
#Override
public void onReleased(int i, File file) {
String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy??-MM-dd HH:mm:ss.SSS"));
System.out.println(instance + "> " + currentTime + ": " + Thread.currentThread().getName() + " onReleased called for file: " + file.getAbsolutePath() + " for cycle: " + i);
if(instance.equals("Reader")) {
System.out.println("Removing previous CQ file: " + file.getName() + ", deleted? " + file.delete()); //==> Not able to delete the file !!!
}
}
.....
Don't know whether this is an optimal solution, please let me know if there is a cleaner way, but the following works [except it will have to loop few times before deleting, as the file is actually released after few milliseconds it seems, i see "file is closed" printed few time before the actual delete happens)
#Override
public void onAcquired(int cycle, File file) {
String currentTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS"));
System.out.println(instance + "> " + currentTime + ": " + Thread.currentThread().getName() + " onAcquired called for file: " + file.getAbsolutePath() + " for cycle: " + cycle);
if(prevCycleFile != null && instance.equals("Reader")) {
System.out.println(">>> Trying to remove: " + prevCycleFile);
boolean bDelete;
while((bDelete=prevCycleFile.delete())==false) {
System.out.println(">>> file is closed");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
System.out.println(">>> Removing previous CQ file: " + prevCycleFile.getAbsolutePath() + ", deleted? " + bDelete);
}
}
It's reasonable to expect a small delay between the Queue reporting that a file is released, and the OS actually detecting/acting upon it.
The StoreFileListener is invoked on the same thread that is reading or writing to the queue, so you will incur latency while the while loop is executing. You'll get better results by handing off the work of closing files to another thread (e.g. via a j.u.c.ConcurrentLinkedQueue).
I am tring to add screenshot, whenever my testcases are getting failed. However i have succeeded doing this in Windows env, but i am unable to achieve it in docker/linux env.
code for screenshot:
public void testFailure(Failure failure) throws java.lang.Exception
{
Random rand = new Random();
//Scenario scenario;
System.out.println("Execution Failure : ");
try {
//String screenshotName = failure.getTestHeader().toString();
int num = rand.nextInt(10000000);
String screenshotName = "Screenshot"+num;
/*File sourcePath = ((TakesScreenshot)Homepage.driver).getScreenshotAs(OutputType.FILE);
File destinationPath = new File(System.getProperty("user.dir") + "/target/CucumberExtentReport/Screenshots/" + screenshotName +".jpeg");
Files.copy(sourcePath, destinationPath);
Reporter.addScreenCaptureFromPath(destinationPath.toString());
*/
final byte[] screenshot = ((TakesScreenshot)Homepage.driver).getScreenshotAs(OutputType.BYTES);
File destinationPath = new File(System.getProperty("user.dir") + "/target/CucumberExtentReport/Screenshots/" + screenshotName +".jpeg");
FileUtils.writeByteArrayToFile(destinationPath, screenshot);
//Files.copy(sourcePath, destinationPath);
Reporter.addScreenCaptureFromPath(destinationPath.toString());
}
catch (Exception e)
{
System.out.println(e.toString());
}
}
Note: I have used extent reports for adding screenshot on failed testcases...
I'm trying to use the subreport component in my main report but does not fire the event SubreportProcessingEventHandler even without any parameter in the sub-report that can generate any errors.
public ActionResult MyReport(DateTime dateReport)
{
var root = Path.GetDirectoryName(this.Server.MapPath("~"));
if (string.IsNullOrEmpty(root))
{
return this.HttpNotFound();
}
var path = Path.Combine(root, "bin\\Reports\\MainReport.rdlc");
if (System.IO.File.Exists(path))
{
this.reportViewer.LocalReport.ReportPath = path;
}
else
{
return this.View("Index");
}
this.LoadData(dateReport);
var reportType = "PDF";
string mimeType;
string encoding;
string fileNameExtension;
var deviceInfo = "<DeviceInfo>" + " <OutputFormat>" + reportType + "</OutputFormat>"
+ " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>"
+ " <MarginTop>0.2in</MarginTop>" + " <MarginLeft>0.4in</MarginLeft>"
+ " <MarginRight>0.4in</MarginRight>" + " <MarginBottom>0.1in</MarginBottom>"
+ "</DeviceInfo>";
Warning[] warnings;
string[] streams;
var renderedBytes = this.reportViewer.LocalReport.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return this.File(renderedBytes, mimeType);
}
private void LoadData(DateTime dateReport)
{
........
this.reportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(this.MySubreportEventHandler);
this.reportViewer.LocalReport.DataSources.Add(new ReportDataSource("UserDataSet", users.DistinctBy(u => u.UserName)));
this.reportViewer.LocalReport.DataSources.Add(new ReportDataSource("EluateReportDataSet", radiopharmacyEluateReports));
this.reportViewer.LocalReport.DataSources.Add(new ReportDataSource("MarkingProtocolReportDataSet", radiopharmacyMarkingProtocolReports));
this.reportViewer.LocalReport.Refresh();
}
public void MySubreportEventHandler(object sender, SubreportProcessingEventArgs e)
{
.....
e.DataSources.Add(new ReportDataSource("RadiopharmaceuticalQualityControlDataSet", radiopharmacyReportQualityControls));
}
I have checked the output and this warning is raised:
Warning: Warnings occurred while executing the subreport ‘Subreport1’. (rsWarningExecutingSubreport)
After more detailed observation, i noticed that subreport really need an parameter that matches with a parameter passed by main report. Without any parameter the subreport just don't work.
How can I download the "RDL report files" from SQL Report Server 2008 programatically (vb.net).
I just need to download all reports and upload all back in one click event. Is this possible?
Several times, I have used a program called SSRSExtractor (open source). It is available on CodeProject.com http://www.codeproject.com/Articles/339744/SSRS-Downloading-RDL-Files
I also had some code before to download reports from ssrs server
public void SaveAdhocReportsToFile()
{
string inputPath = "Reports";
string outPutDir = "D:\\Reports\\";
ExportListItemToFiles("/" + inputPath, ".rdl", outPutDir, ItemType.Report);
}
private void ExportListItemToFiles(string inputPath, string fileExtension, string outPutFolder, string itemType)
{
try
{
Console.WriteLine("Exporting " + itemType + " from SSRS - folder " + inputPath + " to " + outPutFolder);
string outPutFile = string.Empty;
List<CatalogItem> items = ReportService.ListChildren(inputPath, false).Where(x => x.TypeName == itemType).ToList();
foreach (CatalogItem item in items)
{
byte[] rpt_def = null;
XmlDocument doc = new XmlDocument();
rpt_def = ReportService.GetItemDefinition(item.Path);
MemoryStream stream = new MemoryStream(rpt_def);
outPutFile = string.Format(#"{0}{1}" + fileExtension, outPutFolder, item.Name);
if (File.Exists(outPutFile))
File.Delete(outPutFile);
doc.Load(stream);
doc.Save(outPutFile);
}
}
catch (SoapException ex)
{
throw new Exception(ex.Message);
}
}
You can refer to ReportingService2010 Methods: https://msdn.microsoft.com/en-us/library/reportservice2010.reportingservice2010_methods%28v=sql.120%29.aspx
I am making a registration page and while using an input tag to upload image of the user, it is giving an error while running the website: "NullReferenceException was unhandledby user code". Please help me to sort this out. The method which is giving error is:
protected void Button2_Click(object sender, EventArgs e)
{
var path = "Memberimg";
string fn = System.IO.Path.GetFileName(f1.PostedFile.FileName);
string SaveLocation = Server.MapPath("Memberimg") + "\\" + fn;
if ((f1.PostedFile != null) && (f1.PostedFile.ContentLength > 0))
{
try
{
f1.PostedFile.SaveAs(SaveLocation);
Response.Write("The file has been uploaded.");
}
catch (Exception ex)
{
Response.Write("Error: " + ex.Message);
}
}
else
{
Response.Write("Please select a file to upload.");
}
}
You are referring to f1.PostedFile before checking to see if it is null, in the line with:
string fn = System.IO.Path.GetFileName(f1.PostedFile.FileName);