Is it possible send file from C# application over Skype? I searched several topics but I haven't found any solution.
either try to open file dialog in attached skype client:
var skype = new SKYPE4COMLib.Skype();
skype.Client.OpenFileTransferDialog("TargetUserHandle", "sourcePath");
or try to send the contents (1) via Stream in C# or (2) via Stream in pas
else you have to use (3) Skype Kit SDK - requires C/C++
[(1) and (3) worked for me]
Related
I am making an app that allows you to open and edit a pdf file on tablets. Because i usually work with .NET, i decided to write it in .NET MAUI. That way i also have access to windows tablets.
It uses Itext as its main library to read and edit the pdf's.
I have an external shared fileserver that anyone can access when they are coneected to the WIFI.
I'd like to access that fileserver when i connect from my android tablet using Itext pdfreader.
How do I achieve this correctly?
Am i missing a library or a package which would allow to me to access that file?
Are there options i haven't discovered yet?
This works on windows tablets:
string dest "\\\\Path\\to\\File\\";
string file = "\\\\Path\\to\\File\\file.pdf";
PdfDocument pdfDoc = new PdfDocument(new PdfReader(file), new PdfWriter(dest));
I have tried :
string file = Environment.GetFolderPath(Environment.SpecialFolder.Windows)+ "\\Path\to\File\file.pdf";
string file = "\\\\Path\\to\\File\\file.pdf";
All of them result in file not found
Among the getfolderpath options ive tried a dozen, none of them seem to work.
thank you for your time
So i ended up solving this by transforming the document into a base64 string and sending it through an api that i had.
i used the classic httprequest aproach that you can look up and copy anywhere.
I have successfully established a connection to a remote Linux server using the SSH.NET package with the following code (I am using a ShellStream because I have to use sudo su):
using (var client = new SshClient(server, username, password))
{
client.Connect();
List<string> commands = new List<string>();
commands.Add("sudo su - user");
commands.Add("vi test.properties");
ShellStream shellStream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024);
// Execute commands under root account
foreach (string command in commands) {
WriteStream(command, shellStream);
}
client.Disconnect();
}
private static void WriteStream(string cmd, ShellStream stream)
{
stream.WriteLine(cmd + "; echo this-is-the-end");
while (stream.Length == 0)
Thread.Sleep(500);
}
I am trying to edit the test.properties file that is in the remote Linux server using a C# function that I created.
My code (using C# in Visual Studio) that is used to modify the text file is uses System.IO.File.ReadAllText, but it does not recognize the path of the remote server, for example:
The text file in the Linux server is in this location: /home/user/test.properties, so I am using this in my code:
System.IO.File.ReadAllText("/home/user/test.properties")
I am getting the following error:
Could not find a part of the path 'C:\home\user\test.properties'
For some reason it tries to look in my local file system instead of the remote server.
Is there a different approach I should be taking?
Thanks in advance!
In general, to modify remote files, use SFTP. In SSH.NET that's what SftpClient is for.
Though as you seem to need to use elevated privileges (su) – an important factor that your question title fails to mention – it's way more difficult. The right solution is to avoid the need for su. See somewhat related:
Allowing automatic command execution as root on Linux using SSH.
Another option would be to try to execute the SFTP server under su. Though that would require modification of SSH.NET code. See related Java question:
Using JSch to SFTP when one must also switch user
If you want to keep your current shell approach with su, you are stuck with simulating shell commands. Note that connecting to SSH server won't make other .NET classes (like the File) magically be able to work with remote files (even if SFTP was possible, let only when it is not, due to the su requirement).
The easiest way to read remote file using shell is using the cat command:
cat /home/user/test.properties
Alright, so after finishing the task, this is what I did since asking the question here:
1.After your(#Martin Prikryl) response I've tried using a combination of SSH and WinSCP:
WinSCP to download the file.
.NET to modify the locally downloaded file.
WinSCP to upload the file(and deleting it from the local folder afterwards).
SSH to move the file to its appropriate location in the server.
I discarded this solution because it worked pretty well in the lower environment,
but in the production I had permissions issues so I couldn't even download it, let alone that it might be a security issue(its a sensitive file).
2.My next solution was using only SSH to simulate shell commands, as you previously mentioned, I was limited to that because I was stuck using sudo su.
I connected to the server with SSH and used the 'sed' command to only show lines that contain specific words(instead of using cat to get the whole file).
I then used my .NET code to pull the values that I needed for my GET operation
For the POST operation I used 'sed' again to replace lines.
I need C# code to open the WhatsApp desktop application instead of open WhatsApp on the web.
I tried
Process.Start("https://web.whatsapp.com/send?phone=" + textBox1.Text);
but it opens WhatsApp on the web, instead of the WhatsApp Desktop application.
I want to open this link in desktop WhatsApp application
The desktop version of WhatsApp can be found in %LocalAppData%\WhatsApp\Whatsapp.exe.
You get the environment variable with
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Use Path.Combine() to get the backslashes right when combining multiple paths.
Note that the executable above likely just starts another version of WhatsApp.exe. The latest version seems to be in the default key of the Registry at
HKEY_CLASSES_ROOT\whatsapp\shell\open\command
Starting point for an implementation: Registry.ClassesRoot.
Try using the whatsapp protocol:
var process = $"whatsapp://send?phone={textBox1.Text}";
Process.Start(process);
You can append the text argument to send a text:
whatsapp://send?phone=5555555555&text=hello
I'm working on simple application for windows CE to scan barcodes.
I have device: CP9700 and this document: 9700 .NET Programming
There is a simple application which implememt barcode scanner in Appendix II (pages 277 and 278).
I have prepared project in VS2008 and copied program from appendix II.
When I run it on my device I can't catch "WM_DECODEDATA" message.
Can anybody tell me what I'm doing wrong ?
First check the return value of RegisterWindowMessage (see https://msdn.microsoft.com/en-us/library/windows/desktop/ms644947%28v=vs.85%29.aspx for details), if it is 0 you need to use Marshal.GetLastWin32Error() (from System.Runtime.InteropServices) to get an error code. The error codes can be looked up in winerror.h of the installed WMx SDK.
The basic sampe app does not check return codes :-((
YOU should check the InitReader return code (see page 22 of the doc).
Please also check if the DLLs are being copied.
The following happens when decoded data comes about,
A decode event broadcasts when the reader decodes data.
The thread waits for the decode event, and the decode data can then
be obtained.
For example,
while(true) {
dwStatus = WaitForSingleObject(handleEvent,INFINITE)
b1 = Reader.ReaderEngineAPI.GetDecodeType();
b1 = Reader.ReaderEngineAPI.GetDecodeData(ref tmp, tmp.length());
}
Reader DLLs are accessible within the OS directory at the following
paths. Before developing your applications, copy the necessary files
from the mobile computer via ActiveSync connection.
\Windows\Reader_Ce_Net.dll
\Windows\ReaderDll_CE.dll
i need to transfer Text.txt file from PC (using WebService)
to Windows-mobile 5.0 - and from Windows-mobile to PC
can i get any sample code in C# for the WebService and the Windows-mobile ?
thanks in advance
You cannot directly transfer files. you should try ActiveSync RAPI to send information.
Use OpenNETCF. It's a useful compact framework for WindowsMobile (.NET).
Try this:
string fileToSendToDevice = #"C:\Text.txt";
OpenNETCF.Desktop.Communication.RAPI rApi = new OpenNETCF.Desktop.Communication.RAPI();
if (!rApi.DevicePresent) return; // no active sync
if (!rApi.Connected) rApi.Connect();
if (!File.Exists(fileToSendToDevice)) return; // file not found
rApi.CopyFileToDevice(fileToSendToDevice,
Path.Combine(#"\My Documents\", Path.GetFileName(fileToSendToDevice)));
The concept is really no different than PC-to-PC if you intend to use a Web Service for the transfer (assuming the Web Service is running on the PC). Find any example on the web that transfers a file to and from a Web Service and it will likely be applicable.
If you then have a question that is more specific to WinMo/CF or an implementation problem, feel free to update this question about what you've tried and what about it is not working.
One of these two examples will probably help. The code for the PC will be likely the same if not simpler.
Then you just need to write the web service.