How to Upload XML File to TomCat? - c#

I have a TomCat server running a couple of webapps.
I would like to upload an XML file onto my TomCat server so I can access and download the file with a program I am developing in C#.
I've done a lot of searching and I have no solid leads, so how do I upload a file to a Tomcat server so it can be accessed?
For example, I want my program to be able to use this:
get file from(http://tomcat-ip:port/example/data.xml)
Thank you.
Figured out the solution: Place the file in webapps/root and you will be able to access the file from hostname:port/filename

If you are running your tomact server in XAMPP you can put your xml file in C:\xampp\htdocs
code:
URL oracle = new URL("http://localhost/data.xml);
BufferedReader in = new BufferedReader(
new InputStreamReader(oracle.openStream()));
while ((inputLine = in.readLine()) != null)
{
Sysetm.out.println(inputLine);
}
in.close();
If you have html table too you can make array:
Document doc = Jsoup.parse(inputLine);
Elements tables = doc.select("table");
for (Element table : tables) {
Elements trs = table.select("tr");
String[][] trtd = new String[trs.size()][];
for (int i = 0; i < trs.size(); i++) {
Elements tds = trs.get(i).select("td");
trtd[i] = new String[tds.size()];
for (int j = 0; j < tds.size(); j++) {
trtd[i][j] = tds.get(j).text();
}
}
// trtd now contains the desired array for this table
System.out.println(trtd[column][row]);
}

Related

Load an excel file that contains charts and insert new column using Infragistics.Documents.Excel

I would like to insert a new column in an existing file that contains charts.
It doesn't work, visual studio keeps running forever. I noticed that if I delete the charts that are in the loaded file it works just fine. A new column with data is inserted. I just don't know If I can conclude that it's because of existing charts that new columns can't be inserted.
Here is what I did :
private static void Main()
{
string outputFile = "metrics.xlsx";
Workbook workbook = Workbook.Load(outputFile);
Workbook temporary = SetIndicatorsWorkbook();
var values = new List<int>();
for(int j=0; j<12; j++)
{
values.Add((int)temporary.Worksheets["Unit & Integration Tests"].Rows[j].Cells[0].Value);
}
var worksheet = workbook.Worksheets["Unit Testing"];
var k = 9;
var count = worksheet.Rows[14].Cells.Count(cell => cell.Value!=null);
worksheet.Columns.Insert(count+1);
foreach (var value in values)
{
worksheet.Rows[k].Cells[count+1].Value = value;
k++;
}
workbook.Save(outputFile);
}
Your code seems fine, I used a random excel file that had a chart on the sheet and the code executed fine without errors. I will be able to assist further if you provide the metrics.xlsx file.

Could not load type 'SAS.LanguageServiceCarriageControl' from assembly

In addition to using the integration components of SAS Enterprise Edition, I am using parts of the following project I found on Github to connect with a SAS server. The goal here is to command the server to run programs on a schedule. However, the programs need to be modified each time, which is why I am attempting to trigger them to run in this manner. However, it keeps throwing an error at lang.FlushLogLines.
https://github.com/cjdinger/SasHarness
SAS.Workspace ws = server.Workspace;
List<string> results = new List<string>();
Array CCs;
Array lineTypes;
Array logLines;
int maxLines = 100;
SAS.LanguageService lang = (SAS.LanguageService)ws.LanguageService;
Array linesVar = (Array)new string[] { PROGRAM_TEXT };
lang.SubmitLines(ref linesVar);
//THROWS AN ERROR HERE
lang.FlushLogLines(maxLines, out CCs, out lineTypes, out logLines);
for (int i = 0; i < logLines.Length; i++)
{
results.Add((string)logLines.GetValue(i));
}
After a bit of research I found the following thread where it is recommended to make sure that all the required dlls are referenced in my project. The mystery here is that I do have them referenced, but the error still occurs.
http://blogs.sas.com/content/sasdummy/2013/06/09/sas-client-with-microsoft-dot-net/
Moreover, starting after the very first line, the code is no longer using SASHarness, but is using native SAS integration libraries only. The code above is also based on examples listed in the following documentation from SAS.
https://support.sas.com/documentation/cdl/en/itechwcdg/61500/PDF/default/itechwcdg.pdf (page 27-28)
Has anybody encountered an error similar to this, and if so, how did you correct it?
Strangely, fixing this error required declaring an instance for each of the assemblies that could not be loaded. I have no idea why this fixes the problem, but it works now.
SAS.Workspace ws = server.Workspace;
string wsId = ws.UniqueIdentifier;
List<string> results = new List<string>();
Array CCs;
Array lineTypes;
Array logLines;
int maxLines = 100;
SAS.LanguageService lang = (SAS.LanguageService) server.Workspace.LanguageService;
Array linesVar = (Array) new string[] { PROGRAM_TEXT };
lang.SubmitLines(ref linesVar);
//For some reason, these two declarations need to be here
SAS.LanguageServiceCarriageControl CarriageControl = new SAS.LanguageServiceCarriageControl();
SAS.LanguageServiceLineType LineType = new SAS.LanguageServiceLineType();
lang.FlushLogLines(maxLines, out CCs, out lineTypes, out logLines);
for (int i = 0; i < logLines.Length; i++)
{
results.Add((string) logLines.GetValue(i));
}

VSTO 2010 for MS Project

I am using VSTO 2010 for MS Project.Iam loading tasks from sql server.Which will be loading data row by row.It slows the performance as it is loading task one by one.has Everyone any idea about how to load data in one go.
Thanks in Advance.
don't load row by row. Load it table by table... Let your SQL-server do all the hard work-its designed to.
I am using something like below:
MSProject.Tasks mspTask = Globals.ThisAddIn.Application.ActiveProject.Tasks;
for (int i = 0; i < dsTaskList.Tables[0].Rows.Count; i++)
{
DataRow drTask = dsTaskList.Tables[0].Rows[i];
short outLevel = Convert.ToInt16(drTask["TASK_OUTLINE_LEVEL"]);
if (outLevel == 0)
{
continue;
}
mspTask.Add();
Utility.Save_UID.Add(drTask["TASK_UID"].ToString());
Utility.editText9Bycode = true;
mspTask[k].Text9 = drTask["TASK_UID"].ToString();
string strAss = "";
DataSet dsAss = WebServiceCall.GetAssignments(drTask["TASK_UID"].ToString());
}

Using C#, how do I determine if an uploaded file has any accessible metadata/document properties?

Suppose I have a program which allows a user to upload any kind of file. Along with getting generic information such as file type and file size, I would like to attempt to grab any extra information (such as document properties like author, last revised, etc) that may be transported along with the document.
Since I don't have any knowledge about the incoming document/file ahead of time, I can't simply use classes that are specific to, say Microsoft Office docs. I need to do this generically and then construct a dynamic object or dictionary to hold any found key/value results.
Is this possible? If so, how? Any help is appreciated!
I found a few answers on StackOverflow for this, but none gave me a nice, clean dictionary of document properties. Here is what I finally came up with and it seems to be working nicely (you will need to reference "Microsoft Shell Controls and Automation" from the COM folder and add using Shell32; to your code:
public static Dictionary<string,string> GetDocumentMetadata(string fileName)
{
var properties = new Dictionary<string,string>();
var arrHeaders = new List<string>();
var shell = new Shell();
var objFolder = shell.NameSpace(HttpContext.Current.Server.MapPath("~/RawFiles"));
var file = objFolder.ParseName(fileName);
for (var i = 0; i < short.MaxValue; i++)
{
var header = objFolder.GetDetailsOf(null, i);
if (String.IsNullOrEmpty(header))
break;
arrHeaders.Add(header);
}
for (var i = 0; i < arrHeaders.Count; i++)
{
var value = objFolder.GetDetailsOf(file, i);
if (!String.IsNullOrEmpty(value))
{
properties.Add(arrHeaders[i], value);
}
}
return properties;
}

Generate charts with Google chart API

i'am trying to generate a chart like this one: http://chartpart.com/ but i don't know how to do that exactly.Do i need to make the string that generates the chart manually or do i need to send the data to a google server and receive the string?(if so how do i send the data?)
PS:i would like to do all this in c# and send the resulting string via web service.
apparently you need to generate the string yourself.I did just that and send the result to android via web service.
[WebMethod]
public ChartsClass GetChart(string UserId)
{
ChartsClass chart = new ChartsClass();
DataSet1TableAdapters.WS_ChartIndicatorsTableAdapter adapter = new DataSet1TableAdapters.WS_ChartIndicatorsTableAdapter();
DataSet1.WS_ChartIndicatorsDataTable table = adapter.GetChartIndicators(UserId);
StringBuilder sbDescriptions = new StringBuilder();
StringBuilder sbValues = new StringBuilder();
for(int i= 0 ;i< table.Rows.Count ;i++)
{
DataSet1.WS_ChartIndicatorsRow chartRow = (table.Rows[i] as DataSet1.WS_ChartIndicatorsRow);
if (i > 0)
{
sbDescriptions.Append("|");
sbValues.Append(",");
}
sbDescriptions.Append(chartRow.SectorId + " - " + chartRow.SectorDescription );
sbValues.Append(chartRow.NetSaleValue.ToString());
}
chart.ChartString = String.Format("http://chart.apis.google.com/chart?cht=p3&chtt={0}&chd=t:{1}&chs=480x200&chl={2}&chco=ff0000,0000ff",
"Live Sales", sbValues.ToString(), sbDescriptions.ToString());
return chart;
}
And in android you can load the result in a web view.
chartView = (WebView)findViewById(R.id.activity_chart_view);
ChartsClass chart = new ChartsClass(soapObject);
chartView.loadUrl(chart.chartStringSource);
If you are trying to create a chart with user input, there's a wikiHow on that
wikiHow Link: http://www.wikihow.com/Make-a-Google-Chart-with-User-Input
The graph this wikiHow creates is the same as the one on this website:
Website Link: http://www.quickcompromise.com/index.html

Categories