|
1) Unless it's a user control, you almost never use a StackPanel as a "top" content control (of a window); you usually use a Grid; 2 columns in your case. (StackPanels tend to stretch beyond the client area if not "contained").
2) You're confusing the "DataContext" (of a UI Element) with the "ItemSource" of a list-type control.
c# - Show the contents of xml file in wpf window - Stack Overflow
"(I) am amazed to see myself here rather than there ... now rather than then".
― Blaise Pascal
|
|
|
|
|
|
how to work with ms word add in in c# and how to get data from exel(using excel as database)
|
|
|
|
|
|
I'd say... normally... or as usual...
All what you need to do is to create MS Excel application instance, open workbook, provide several operation (for example: copy data between apps), etc. Finally, you need to close a workbook and then close an instance of MS Excell application. Do not forget to clean up by calling below code:
GC.Collect();
GC.WaitForPendingFinalizers();
Marshal.ReleaseComObject(xlSheet);
Marshal.ReleaseComObject(xlBook);<br />
Marshal.ReleaseComObject(xlApp);
Good luck!
|
|
|
|
|
I have the following API Controller with a simple method to accept a file via the IFormfile, which works a treat in Postman. Now I need to call this with a HttpClient call from a console application.
[HttpPost]
public IActionResult PostFile(IFormFile file)
{
Return OK();
}
This is where I am stuck can anyone give me a good couple of examples of creating a PostAsync call so that I can transfer a file to the server?
Thanks
Simon
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
Something like this should work:
public static async Task UploadFile(HttpClient client, string url, string filePath, string contentType, CancellationToken cancellationToken)
{
using (var fileStream = File.OpenRead(filePath))
{
var file = new StreamContent(fileStream);
file.Headers.ContentType = MediaTypeHeaderValue.Parse(mimeType);
file.Headers.ContentLength = fileStream.Length;
var content = new MultipartFormDataContent();
content.Add(file, "file", Path.GetFileName(filePath));
using (var response = await client.PostAsync(url, content, cancellationToken).ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
}
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard,
Thanks for this and apologies that I have taken so long to respond, had to tweak your solution slightly to make it work
using (var formData = new MultipartFormDataContent())
{
Task<HttpResponseMessage> responseMessage = null;
using (var stream = File.OpenRead(pdf))
{
HttpContent fileStreamContent = new StreamContent(stream);
fileStreamContent.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("form-data")
{ Name = "DigitalPCN", FileName = Path.GetFileName(fine.FileName) };
fileStreamContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf");
formData.Add(fileStreamContent);
responseMessage = base.PostAsync(new Uri(@"https://localhost:44349/api/Controller/Method"), formData, token);
responseMessage.Wait();
}
return responseMessage.Result;
}
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
hello!
i am blind and I am trying to develop a simple SSH client which will help people like me with SSH coomunications.
I am using the Netssh library to achieve this. The following code seems to be faulty, because I get either no error or connection validation.
CODE:
using DavyKager;
using Renci.SshNet;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mao_TTY
{
public partial class DLGConnect : Form
{
public DLGConnect()
{
InitializeComponent();
}
private void DLGConnect_Load(object sender, EventArgs e)
{
Tolk.Load();
}
private void BTNConnect_Click(object sender, EventArgs e)
{
string Address = TXTHost.Text;
string Port = TXTPort.Text;
string UserName = TXTUserName.Text;
string Password = TXTPassword.Text;
int NumPort = Int32.Parse(Port);
SshClient SSHObj = new SshClient(Address, NumPort, UserName, Password);
SSHObj.Connect();
if (!SSHObj.IsConnected)
{
MessageBox.Show("Wystąpił błąd połączenia z serwerem.\nSprawdź czy wszystkie wprowadzone dane są poprawne i spróbuj ponownie", "Błąd");
}
}
}
}
|
|
|
|
|
The SSHObj goes out of scope; the variable is "lost" once the method ends, and is disposed of, connected or not. Try something like below;
SshClient SSHObj = null;
private void BTNConnect_Click(object sender, EventArgs e)
{
string Address = TXTHost.Text;
string Port = TXTPort.Text;
string UserName = TXTUserName.Text;
string Password = TXTPassword.Text;
int NumPort = Int32.Parse(Port);
SSHObj = new SshClient(Address, NumPort, UserName, Password);
SSHObj.Connect();
}
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Hello,
it still behaves in the same way (when I click connect and values are incorrect, no error in the if statement is raised.)
|
|
|
|
|
What SSH-client are you using? I'd recommend SSH.NET
Also, what are you expecting the thing to do if there is a connection? How about running a command?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
i am using SSHNet. I want to write a full-fledged client but for now I just would like to test if it works.
|
|
|
|
|
The connect-command will not show a dialog stating that it is connected. If you want to test it, you got to use the connection. There's samples available on the site where you downloaded SSH.NET.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
Ah, I thout that "IsConnected" property will give me the result I want.
|
|
|
|
|
If the "connect" method is blocking, then yes. If connected, then "nothing" would happen, since the "if" doesn't have an "else" part.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
I'm putting a quote together to scan some multi-part forms that are Dot Matrix printed and OCR the packing list number off them for later processing. All I need is the one number off it. Once I have the number I can lookup the contents.
The original intention was to write a c# winforms app, have the op drop the packing lists in the Kyocera copier scanner and save the images to a folder on the server. Then run the app and OCR each image and rename them and store them for recall.
I wrote a test program and tried the Microsoft Ocr, the Iron Ocr, dabbled with the Matrox MIL but backed off it because it required way more time to learn. I can get partial numbers but never got a complete number.
I understand that the 9 pin dot matrix is really low resolution and doesn't create perfect type.
Thought about trying to reprogram the printer to produce letter quality dot matrix on just the number, but it's DOS program and I'm not sure if I can change the template without recompiling the program; I don't know how to compile old Foxpro.
Maybe I'll drop the OCR idea and go another direction.
Does anyone have any experience with this? Any Ideas?
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
jkirkerx wrote: 9 pin dot matrix Wow that is so 80s tech. I am not surprised you are having trouble getting OCR to read it. I would suggest going to ink jet/laser but I guess multi part forms are embedded in their procedures.
Can you up the contrast on the printer, or get the printer to add a bar code although that will probably be as difficult to read as well.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
I found the printer code template for that form yesterday and I think I can edit it and go without compiling.
Make that number bold and letter quality LQ.
I'm going to a manufacture Thursday, Viewsonic and I'll take a look at how they do it.
I'm thinking about laser printing the form on colored NCR paper, changing the print process and media.
Yes very 80's. But the accounting program is rock solid however and very lightweight.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
It seems like you should ditch the old FoxPro if you can, especially since you don't know
how to compile. You might search google on "compiling FoxPro"; you might get lucky.
Don't know how old your printer is but some manufacturers like the one I use to work for
had some models with built in resident ocr even on some of their 9 pin models.
They did this because of the reason you describe of low quality and the resident ocr was tuned
in the printer software to get the best quality from the printer. But still it wasn't the best but was usually readable on the first copy but it was 'ify' to whether it would read on more than the first or second copy of the multicopy form.
So you might check you printer features to see if it supports ocr.
Also most printers have a printer specific escape command that will put the printer into letter
quality mode. You will have to look at your printers command reference to see if it supports that.
It's usually a simple sequence to send to the printer.
And some printers have the ability to select these features from their front panel feature list;
that is if they have one. However this puts some of the responsibility of setting up the printer
onto the user which is usually undesireable because users don't really like to mess with setup
procedures.
Hope this helps
Best regards
-- modified 21-Jan-19 21:43pm.
|
|
|
|
|
I'll go that road for half a day and do the research on escape codes. Did it once back in 1987, should be able to do it again. I'll look into printers as well. But the above post explains my other idea.
Thanks for your suggestions!
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
I once created a .net application using a combination of AForge imaging library to crop the area of the page I needed and do some image processing to sharpen the cropped image, before running it through Tesseract.net to OCR, it worked suprisingly well but took a bit of calibration to get the image filters/manipulation set up to get the best results.
|
|
|
|
|
That sounds promising. I thought about photoshop or something.
I'm gonna start running down the list of experiments tomorrow.
If it ain't broke don't fix it
Discover my world at jkirkerx.com
|
|
|
|
|
If you are still considering OCR as an approach, the LEADTOOLS OCR toolkit has a native recognition module specifically for 9 Pin Dot Matrix text that may give good results for you. (Disclaimer: I am an employee of the vendor of this toolkit).
This native recognition module is part of the LEADTOOLS OmniPage OCR Engine and can be set when determining recognition zones for a particular OCR document.
The code to set this type of zone will look like this:
using (RasterCodecs codecs = new RasterCodecs())
{
codecs.Options.Load.XResolution = 300;
codecs.Options.Load.YResolution = 300;
codecs.Options.Load.AllPages = true;
RasterImage sourceFile = codecs.Load(fileName);
_ocrDocument.Pages.AddPages(sourceFile, 1, -1, null);
OcrZone ocrZone = new OcrZone();
ocrZone.Bounds = new LeadRect(50, 50, 300, 100);
ocrZone.ZoneType = OcrZoneType.Text;
_ocrDocument.Pages[0].Zones.Add(ocrZone);
NativeOcrZone dotMatrx = new NativeOcrZone();
dotMatrx.Bounds = ocrZone.Bounds;
dotMatrx.ZoneType = NativeOcrZoneType.Text;
dotMatrx.RecognitionModule = NativeOcrZoneRecognitionModule.DotMatrix;
_ocrEngine.ZoneManager.SetNativeZone(_ocrDocument.Pages[0], 0, dotMatrx);
}
|
|
|
|
|
Wow $6k to get the engine and the OCR add on for a single user is well beyond what I would have expected. Note the OP is either an independent developer or a very small shop, unless he can get a client to pay for it I'd be astonished if 6k was acceptable.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|