Issue downloading files with WebClient - c#

Tested WebClient on both project type (WPF,Windows form application)
With the below code:
String[] txt = { "someURLstring", "otherURLstring" };
foreach (String str in txt)
{
using (WebClient wc = new WebClient())
{
wc.DownloadProgressChanged += wc_DownloadProgressChanged;
wc.DownloadFileCompleted += wc_DownloadFileCompleted;
await wc.DownloadFileTaskAsync(new Uri(str), "somename.rar");
}
}
Both projects are developed using Visual Studio 2015 with .net framework 4.5 on windows 10.
The issue is that, when those applications are not running on the PC that they are developed, the files that are downloaded are 95 KB each, but they are 2.5 MB each.
I tried to build them using .net framework 4.6 but still same issue.
Any ideas?
Both are tested on 2 other PC's using windows 7/10 with .net framework 4.6
EDIT:
I changed links to download files from my own webserver (file are .zip) and everything worked fine. Previous links though work only on my PC.
Any ideas?
Ok, well my bad I didn't mention that the first links that were used come from mediafire. Though they are using captcha system that's why other users can't download the files.

Related

SFTP download with .NET CORE 3.1

Is there a way to download a file from a sftp server with .net core 3.1 ?
I found various answers which are all outdated. (for example, ssh.net cannot be found anymore)
How is the current status in this topic?
There is an updated version of SSH.net called Neon.SSh.Net
https://www.nuget.org/packages/Neon.SSH.NET/
works in the same way as the old version from Renci.
...
var client = new SftpClient(host,port,username,password);
client.Connect();
using (Stream fileStream = File.OpenWrite("c:\\temp\\file.tmp"))
{
_client.DownloadFile(ftpFilePath, fileStream);
}
...

How to deploy a .net dll, which invokes UWP OCR API in it?

I have a .NET-wrapper library based on .NET Framework v4.6.1, which invokes UWP OCR API. It contains only one class with one function in it, code is below
public static async Task<string> ExtractText(Stream stream, string language)
{
using (IRandomAccessStream uwpStream = new InMemoryRandomAccessStream())
{
byte[] input = new byte[stream.Length];
stream.Read(input, 0, input.Length);
uwpStream.AsStreamForWrite().Write(input, 0, input.Length);
uwpStream.AsStreamForWrite().Flush();
uwpStream.Seek(0);
BitmapDecoder decoder = await BitmapDecoder.CreateAsync(uwpStream);
SoftwareBitmap bitmap = await decoder.GetSoftwareBitmapAsync();
OcrEngine engine = OcrEngine.TryCreateFromLanguage(new
Language(language));
uwpStream.Dispose();
if (engine != null)
{
OcrResult result = await engine.RecognizeAsync(bitmap);
return result.Text;
}
else
{
throw new NullReferenceException("Language is not supported");
}
}
}
Project has links to following UWP libraries: Windows.WinMD, Windows.Foundation.FoundationContract.winmd, Windows.Foundation.UniversalApiContract.winmd. I found their location via object browser in Visual Studio, copied them from their original location to subfolder in my project and then linked them.
My app runs ok on my local machine and UWP OCR Engine works fine.
Then I deploy my library and an application, which uses it, on my virtual machine, which has Windows Server 2012 R2 on it with installed .NET Framework and installed Windows 10 SDK.
My program fails during runtime with the exception:
Could not find Windows Runtime type "Windows.Graphics.Imaging.SoftwareBitmap"
To solve the problem I tried to reinstall Windows 10 SDK on my virtual server and checked that versions match exact versions on my development machine.
It seems like some of the .winmd libraries does not load in runtime.
I expect my program to run successfully on another machine in release mode.
It works on development machine fine.
However, I am new to UWP, so maybe initial information is not enough to solve the problem, but I'm ready to provide more.
Any help would be appreciated
I was able to make my UWP OCR work on Windows Server 2019
It seems like Windows Server 2012 R2 does not support all the functional of Windows 10 SDK
At least my program could not load all the .winmd files required in runtime
Migration to Windows Server 2019 makes it work without any problems

Use UWP in WPF Application Throws Error "generating manifest"

I want to use the OCR component of UWP in an WPF C# app.This is done by using a C# class library in other projects. On build I get the following error shown below. How can I get this to compile?
Error 1 Problem generating manifest. Could not load file or assembly
'{MyAppPath}\Windows.winmd' or one of its dependencies. Attempt to
load a program with an incorrect format.
The picture shows the references:
The files are:
System.Runtime.WindowsRuntime: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
System.Runtime.InteropServices.WindowsRuntime: C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.1\Facades\System.Runtime.InteropServices.WindowsRuntime.dll
Windows: C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
The Code I want to use (not in a finsished state, I just want it to compile)
using System;
using Windows.Graphics.Imaging;
using Windows.Media.Ocr;
using Windows.Storage;
namespace tegBase
{
public class Scan
{
public static async void OcrAusfuehren()
{
var fileName = #"C:\a.jpg";
StorageFile file = await StorageFile.GetFileFromPathAsync(fileName);
var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);
var decoder = await Windows.Graphics.Imaging.BitmapDecoder.CreateAsync(stream);
SoftwareBitmap b;
b = await decoder.GetSoftwareBitmapAsync();
OcrEngine ocrEngine = OcrEngine.TryCreateFromUserProfileLanguages();
var s = await ocrEngine.RecognizeAsync(b);
Windows.Media.Ocr.OcrResult c = s;
Console.WriteLine(c.Text);
}
}
}
Update:
I tried to reproduce the error on another PC, there however, the UnionMetadata folder is empty. So I took the winmd from 10.0.16299.0, but it lead to the same result.
I also tried changing the target framework from .net 4.5.1 to 4.6.1, which also did not solve the problem. On a sidenote: changing it to 4.7.1 was not possible, as VS said it was not installed. Installing 4.7.1 was also not possible, with the installer message beeing: Higher Version already installed.
You need to download the UWP software development kit (SDK) and migrate the package to package references. This must be done in order to use all the UWP libraries within a WPF/WinForms/Console application. Please visit this website for a step-by-step tutorial: https://www.thomasclaudiushuber.com/2019/04/26/calling-windows-10-apis-from-your-wpf-application/

how to get connect with ibm websphere mq by using c#.net

can any one guide me on, to get connect with ibm websphere mq by using c#.net, reason was i am trying to push the message in to MQ, kindly can any give me suggestion to connect by using c#.net
There is an IBM supplied dll (since v5.3 Fixpack8) on Windows called amqmdnet.dll, which is a .NET assembly providing an IBM supported model for MQSeries. (Reference) It is usually located in C:\Program Files\IBM\WebSphere MQ\bin\amqmdnet.dll
If you need more direction, there are several examples on how to communicate with MQ from .NET on CodeProject:
http://www.codeproject.com/Articles/12198/IBM-WebSphere-MQ-with-C-GUI-application-that-is-bo
http://www.codeproject.com/Articles/37807/How-to-Setup-a-Websphere-MQ-with-C-NET-GUI-to-Put
http://www.codeproject.com/Articles/6212/C-and-WebSphere-MQ-formerly-MQSeries-Client-Server
Also, there's this walkthrough that could be helpful: http://www.c-sharpcorner.com/UploadFile/pk_khuman/AquickstartCsharpWebsphereMQ07112006024017AM/AquickstartCsharpWebsphereMQ.aspx
You can connect using the .NET libraries provided by IBM; however, they require you to install the WebSphere MQ Client on every server you deploy your solution to. (lame)
If using WebSphere MQ, the machine used to run the XMS application
must be installed with the WebSphere MQ Client V7.0.1.0 or later
You can avoid this by converting a few Java libraries using IKVM (www.ikvm.net).
The whole process should only take about 15 minutes.
You'll still need to download and install the client on your development box so that you can get the JAR files. After you convert them, you can uninstall the client.
Here are the steps
1) Get JARs
Download WebSphere MQ V7.5 Client: http://www-304.ibm.com/support/docview.wss?uid=swg24032744
Install the MQ client: You only need to install the "Java and .Net Messaging and Web Services".
2) Convert JARs
Download IKVM: www.ikvm.net
Extract the IKVM files (e.g. c:\tools\IKVM).
Open Win command prompt
Execute command: set path=%path%;c:\tools\IKVM\bin
Execute command: cd C:\Program Files (x86)\IBM\WebSphere MQ\java\lib
Execute command: ikvmc -target:library -sharedclassloader { com.ibm.mq.jmqi.jar } { com.ibm.mqjms.jar } { dhbcore.jar } { jms.jar }
3) Copy JARs
Open windows explorer.
Navigate to: C:\Program Files (x86)\IBM\WebSphere MQ\java\lib
Copy the following files:
**com.ibm.mq.jmqi.dll
com.ibm.mqjms.dll
jms.dll**
Navigate to: c:\tools\IKVM\bin
Copy the following files:
**IKVM.Runtime.dll
IKVM.OpenJDK.Core.dll**
Move the copied files to a 3rd Party folder in your project/solution.
4) References JARs
Reference the copied JARs. Please note that you can skip the previous Copy JARs step above and simply reference the libraries directly, if you like. The objective was to show that there were no other resources needed for proper execution.
The following is a very simple example of how you can use the libraries.
using com.ibm.msg.client.jms;
using com.ibm.msg.client.wmq.common;
using javax.jms;
using System;
class Program
{
static void Main(string[] args)
{
var ff = JmsFactoryFactory.getInstance(JmsConstants.__Fields.WMQ_PROVIDER);
var cf = ff.createConnectionFactory() as JmsConnectionFactory;
cf.setIntProperty(CommonConstants.__Fields.WMQ_CONNECTION_MODE, CommonConstants.__Fields.WMQ_CM_CLIENT);
cf.setStringProperty(CommonConstants.__Fields.WMQ_HOST_NAME, "<YOUR INFO>");
cf.setIntProperty(CommonConstants.__Fields.WMQ_PORT, 1414);
cf.setStringProperty(CommonConstants.__Fields.WMQ_CHANNEL, "<YOUR INFO>");
cf.setStringProperty(CommonConstants.__Fields.WMQ_QUEUE_MANAGER, "<YOUR INFO>");
var connection = cf.createConnection();
var session = connection.createSession(false, Session.__Fields.AUTO_ACKNOWLEDGE);
var queue = session.createQueue("queue:///<YOUR INFO>");
var producer = session.createProducer(queue);
var msg = session.createTextMessage();
msg.setStringProperty("JMSXGroupID", Guid.NewGuid().ToString());
msg.setIntProperty("JMSXGroupSeq", 1);
msg.setBooleanProperty("JMS_IBM_Last_Msg_In_Group", true);
msg.setText("Hello World");
connection.start();
producer.send(msg);
producer.close();
session.close();
connection.close();
}
}
There are number of samples that come with MQ product install. Refer Nmqsput.cs for your case. When creating a new project you will need to add amqmdnet.dll as reference.
Not sure what version of MQ you are using. I am assuming you are using MQ v701. You can find the samples under tools folder of your MQ installation.
If are looking for JMS style of messaging in C#, then XMS .NET is worth looking at. You can find the samples of XMS .NET in the same folder as MQ samples. XMS .NET reference is here
Already converted (java to c#) mq-client -
nuget,
github
c# example:
var ff = JmsFactoryFactory.getInstance(JmsConstants.__Fields.WMQ_PROVIDER);
var cf = ff.createConnectionFactory();
cf.setIntProperty(CommonConstants.__Fields.WMQ_CONNECTION_MODE, CommonConstants.__Fields.WMQ_CM_CLIENT);
cf.setStringProperty(CommonConstants.__Fields.WMQ_HOST_NAME, "127.0.0.1");
cf.setIntProperty(CommonConstants.__Fields.WMQ_PORT, 8010);
cf.setStringProperty(CommonConstants.__Fields.WMQ_CHANNEL, "EXAMPLE.CHANNEL.ONE");
cf.setStringProperty(CommonConstants.__Fields.WMQ_QUEUE_MANAGER, "EXAMPLE_QUEUE_MANAGER");
cf.setStringProperty(CommonConstants.__Fields.WMQ_APPLICATIONNAME, "JMS EXAMPLE");
cf.setStringProperty(CommonConstants.USERID, "EXAMPLE_USER");
using (var context = cf.createContext())
{
var queue = context.createQueue("queue:///EXAMPLE_QUEUE_NAME");
var producer = context.createProducer();
producer.send(queue, "Hello World");
}

Using C# How to detect if Windows Installer 4.5 is Installed

I am trying to figure out the most efficient way to determine if Windows Installer 4.5 is installed on a machine.
I have a 2.0 application (cannot convert at this time to 3.5) and we are upgrading from MSDE to SQL 2008 Express. One of the requirements of 2008 Express is that Windows Installer 4.5 is installed on the machine. This application is deployed globally to machines both on and off of an internal network.
I would prefer to run a batch file or C# code to determine the installer version.
Please let me know your recommended methods and provide some code (or links to code).
Thanks!
You can read the file version of the msi.dll library in the system directory:
using System.Diagnostics;
using System.IO;
public bool IsWindowsInstaller45Installed()
{
FileVersionInfo info;
string fileName = Path.Combine(Environment.SystemDirectory, "msi.dll");
try {
info = FileVersionInfo.GetVersionInfo(fileName);
} catch (FileNotFoundException) {
return false;
}
return (info.FileMajorPart > 4
|| info.FileMajorPart == 4 && info.FileMinorPart >= 5);
}
Check the version of the MSI.DLL file that's in your System32 directory.
You should be able to use GetFileVersionInfo or GetFileVersionInfoEx to get out the version number.
This MSDN article has some sample code: Unsafe Code Tutorial
Like Ho1 said, you can go by the version of MSI.dll in System32 but you don't need to P/Invoke you can use the FileVersionInfo class found in System.Diagnostics.

Categories

Resources