c# idm using 'batch download from clipboard'(one of idm's functions) - c#

I want to make a program using C# (Windows Forms App) that if I click a button, assume that there are some addresses that I want to download in my clipboard already, then using 'batch download from clipboard' function, start downloading with IDM.
Anybody please help me to make it.
Batch download from clipboard

you should let operating system to decide which program to run. it will open a default browser and if the address has some file to download it will open your IDM.in "if" section, you can add some checking to see if the address ends with the extension you wanna download . The code-behind will be something like this
private void button1_Click(object sender, EventArgs e)
{
var clipboard = Clipboard.GetText();
if (clipboard.StartsWith("http://"))
{
System.Diagnostics.Process.Start(clipboard);
}
}

Related

Clicking a button on a windows from from a webform

I have created a windows form program that does some Business Intelligence but have subsequently needed to access this via a webform. I am fairly new to programming so I don't know what can be achieved here. But essentially I am wanting someone to go on to the net and when the user presses a button it sends a message to the windows form executable in a file and tells it to run and then press a button on the form, which runs a method to generate images of graphs. Is this possible?
Here is the relevant code.
In the webform I have this button.
protected void rolloutSmartSheets(object sender, EventArgs e)
{
string message = string.Format("Starting processes");
ltMessage.Text = message;
Process process = new Process();
process.StartInfo.FileName = #"P:\Visual Studio 2013\Projects\Smartsheet\SmartsheetAPI\obj\Debug\SmartSheetAPI.exe";
process.Start();
message = string.Format("Ended all processes");
ltMessage.Text = message;
}
That runs the executable but it opens the windows form and I imagine if the executable is sitting on another computer wouldn't that open on that computer? In which case i want it to tell it to press this button on the windows form which runs the method I need and then the user doesn't need to worry about it.
public void commitToDatabase_Click(object sender, EventArgs e)
{
commitToDataBase();
}
If you are able to have the clients install something in advance, you can provide this functionality using a custom protocol handler.
Example protocol handler from MSDN Article
HKEY_CLASSES_ROOT
alert
(Default) = "URL:Alert Protocol"
URL Protocol = ""
DefaultIcon
(Default) = "alert.exe,1"
shell
open
command
(Default) = "C:\Program Files\Alert\alert.exe" "%1"
Then add a link onto your webform like this
href="alert://test"
As long as the client has the handler installed, both in the registry and the executable file, it will run C:\Program Files\Alert\alert.exe, passing "test" to it as the first paramater.
You can easily change this to provide the ability to run the local graph generator, and pass any parameters from the webform you might need.

can record unc connection?

The Pc I use have an UNC file. I'm in a Network with other people.
Every other can open the file by tipping in the adress line \\file.
Know I want to write a c# programm in Vs2010 which watch over the file I use Win7 32bit. If any one Open the file the programm shall write in a Logfile that someone has open my file.
I tried to use the FileSystemWatcher but this only look for changes/saves/cration but not for Opening.
I read somthing about "auditing" and that I'm be able to do that(watch over my unc file) with this(auditing).But i tried to find out how to use auditing in c# but i found not much.
.
So my Questions:
Is it possible to do what i want with "auditing" ?
Did someone worked with auditing in c# befor or has anyone a link or somtihng to show me how it works in c#?
mfg Sam
Sry for bad english
You might want to use the Audit Object Access.
The steps you have to follow:
Enable the Audit object access in the Local Computer Policy.
Enable auditing for the object you want to follow.
From your application, use the EventLog.EntryWritten Event to detect the file opening event
Here's a simplistic sample usage, but you'll have to dig in the documentation in order to capture and log as you need to:
class Program
{
public static void Main()
{
EventLog myNewLog = new EventLog("Security", ".", "Microsoft Windows security");
myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
myNewLog.EnableRaisingEvents = true;
Console.ReadLine();
}
public static async void MyOnEntryWritten(object source, EntryWrittenEventArgs e)
{
await Task.Factory.StartNew(() =>
{
if (e.Entry.InstanceId == 4656 || e.Entry.InstanceId == 4663)
{
Console.WriteLine(e.Entry.Message);
}
});
}
}

C# get notified when another process makes changes to a textfile

I would like to be notified in my C# application when another process makes changes to a particular textfile.
The reason for this is that I launch a 3rd party tool from my application in order to retrieve some information about a device. this tool saves the current state of the device into an ini file. This takes some undetermined time, but I want to react and read the state information as soon as it's available.
How can I do this?
You could use the System.IO.FileSystemWatcher class.
Something like this:
string fileToWatch = #"C:\MyFile.txt";
fileSystemWatcher = new FileSystemWatcher(fileToWatch);
void fileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
{
Debug.WriteLine(e.Name + " has changed");
}
You can monitor file changes using System.IO.FileSystemWatcher
Also, see Notification when a file changes? for more info.

How can i delete the file that has been navigated in a webbrowser control?

How can I delete the file that has been navigated in the webbrowser?
Error says "It is being used by another process"
preview_wb.Navigate(#"C:\mypdf.pdf");
private void close_btn_Click(object sender, EventArgs e)
{
preview_wb.Stop();
File.Delete(#"C:\mypdf.pdf");
}
Usually people suggest this code:
webBrowser.Navigate("about:blank");
while (webBrowser.ReadyState != WebBrowserReadyState.Complete)
Application.DoEvents();
File.Delete(fileName);
I don't like it. I prefer to handle DocumentCompleted event.
void DeleteFile()
{
needToDeleteFile = true;
webBrowser.Navigate("about:blank");
}
void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (needToDeleteFile)
{
File.Delete(fileName);
needToDeleteFile = false;
}
}
If you need the "preview" to persist after the file has been deleted, you probably don't have any choice but to copy the file and navigate to the copy instead.
If you're happy to clear the "preview" when the file is delete, just navigate away from it first:
private void close_btn_Click(object sender, EventArgs e)
{
preview_wb.Navigate("about:blank");
File.Delete(#"C:\mypdf.pdf");
}
That should do the trick.
Have you tried finding the file via the internet explorer cache (using FindFirst/NextUrlCacheEntry API) and deleting it with DeleteUrlCacheEntry? There are pre-written examples on how to loop through and do the deletion on the new, just google it.
You will get 3 types of cache, on starting with "Cookie: ", another starting with "Visited: " - which just represents the visited sites list (it isn't the history, don't confuse the two), and the last type just comes in the form of a url begining with http:// or https://. Once you are looping through, you can pick and choose which ones you want to delete.
Let me know if you have any further questions, doing it this way should get rid of the "file in use" issue, if it doesn't, either .dispose or unload your webbrowser control before doing cache delete (but you probably won't need to).

Is it possible to open a PDF inside a c# application with Acrobat.dll?

I know that I can display a PDF file in my c# executable (not web app) with:
private AxAcroPDFLib.AxAcroPDF axAcroPDF1;
axAcroPDF1.LoadFile(#"somefile.pdf");
axAcroPDF1.Show();
But that is the regular pdf viewer like in the browser. I don't want that. I want full Adobe Standard or Professional functionality in my C# application using the Adobe controls. For example, if I use the code above, it loads in the C# app and I can see the adobe toolbar (print, save, etc.) But it is useless to me because I need things like save which cannot be done with the activex viewer above. Specifically, you cannot save, just as you cannot within the broswer.
So, I referenced the acrobat.dll and am trying to use:
Acrobat.AcroAVDocClass _acroDoc = new Acrobat.AcroAVDocClass();
Acrobat.AcroApp _myAdobe = new Acrobat.AcroApp();
Acrobat.AcroPDDoc _pdDoc = null;
_acroDoc.Open(myPath, "test");
pdDoc = (Acrobat.AcroPDDoc)(_acroDoc.GetPDDoc());
_acroDoc.SetViewMode(2);
_myAdobe.Show();
It opens adobe acrobat but it opens it outside of my c# application. I need it to open in my c# application like the activex library does. Can it be done with these libraries?
If I cannot open it in my c# application I would like to be able to "hold" my c# app tied to it so the c# app knows when I close the adobe app. At least that way I'd have some measure of control. This means I would hit open, the adobe app opens. I close the adobe app, my C# app is aware of this and loads the newly changed doc with the activex library (because I don't need change ability anymore, just displaying.)
I have the full versions of adobe acrobat installed on my computer. It is not the reader.
Thank you for any help.
edit:
There is an example in vb in the adobe acrobat sdk. I believe it is called activeview.
you can check out ABCpdf. I dont know if it has this capability but we have used it for several of our apps
Using a webbrowser control would be an option to display the content.
IText# may help you out.
You can create PDF's and I believe you can use it to read and modify them.
As for displaying in the app..... I am not sure how to display them with iText or if it is possible (have not tried this yet), sorry. iText does let you convert to RTF which may be one approach.
Best option is to write a listener which tells your calling code when Adobe.exe is no longer running. Something like the following (with tweaks for your uses) should work:
public void Open(string myPath)
{
Acrobat.AcroAVDocClass _acroDoc = new Acrobat.AcroAVDocClass();
Acrobat.AcroApp _myAdobe = new Acrobat.AcroApp();
Acrobat.AcroPDDoc _pdDoc = null;
_acroDoc.Open(myPath, "test");
_pdDoc = (Acrobat.AcroPDDoc) (_acroDoc.GetPDDoc());
_acroDoc.SetViewMode(2);
_myAdobe.Show();
NotifyAdobeClosed += new EventHandler(Monitor_NotifyAdobeClosed);
MonitorAdobe();
}
private void Monitor_NotifyAdobeClosed(object sender, EventArgs e)
{
NotifyAdobeClosed -= Monitor_NotifyAdobeClosed;
//Do whatever it is you want to do when adobe is closed.
}
private void MonitorAdobe()
{
while(true)
{
var adcount = (from p in Process.GetProcesses()
where p.ProcessName.ToLower() == "acrobat"
select p).Count();
if (adcount == 0)
{
OnNotifyAdobeClosed();
break;
}
}
}
public event EventHandler NotifyAdobeClosed;
public void OnNotifyAdobeClosed()
{
if (NotifyAdobeClosed != null)
NotifyAdobeClosed(this, null);
}

Categories