|
Thanks,
I will go for "BeginInvoke"
|
|
|
|
|
|
Could someone give me a direction?
I would like to do a log(output to txt file) of Removable Device.
Currently, I am only able to detect whether is there any Removable Device inserted or removed on the computer.
I need to know how to capture like I have move a file or folder from Removable Device to computer or vice verse.
|
|
|
|
|
You're not he first person to ask this. It comes up about every 6 months...
In a nutshell, there's no way to do this. Since a copy operation is no different than opening a file to read it, for example, opening it in Notepad, there's no way to tell if someone is copying a file or not. A move operation is a bit more complex because if the source and destination is on the same volume, the directory entry is moved to its new folder. If done between different volumes, it becomes a copy operation then delete the source file.
Why can't it be done? Because it can't be done reliably. If Explorer does the copy/move, you may be able to hook the shell to see if happens, but that won't catch someone typing COPY or XCOPY in a CMD prompt, nor will it catch any other program that is doing the copy or move.
|
|
|
|
|
Hi Dave,
Thanks for answering.
What if I just want to do a log when there is a move operation from computer to removable devices like thumb drive?
I do not need to log down the movement of the files locally.
Still able to do it?
|
|
|
|
|
No, you can't. There's nothing different about a USB drive compared to any other disk as far as the file system is concerned. A copy operation is still just open a file, read it's contents, and write it to a destination file. There is nothing that is special about a copy operation that you can use as a trigger.
|
|
|
|
|
Sadded. Anyway thanks. Haha.
|
|
|
|
|
|
Won't work for what he's talking about.
|
|
|
|
|
Sure it won't, Dave, but combined with some heuristic I think he might get a good approximation if he doesn't need an exact solution.
|
|
|
|
|
Nowhere near a reliable solution...
|
|
|
|
|
Thanks alot will try it out
|
|
|
|
|
Hello
I have to user controls on the same window and I would like to call a method in user control B from user control A. The method in user control B is public.
At the moment I have no clue how I would go about doing this. Any help would be greatly apreciated.
|
|
|
|
|
I don't have Visual Studio in the laptop I am currently using. But this should work. Main thing is that you will get the idea as to how to do this.
Assume you the following 2 user controls in your .aspx
ParentPage.aspx
<%@ Register src="Control1.ascx" TagPrefix="uc" TagName="Control1" %>
<%@ Register src="Control2.ascx" TagPrefix="uc" TagName="Control2" %>
<uc:Control1 runat="server" ID="ctrl1" />
<uc:Control2 runat="Server" ID="ctrl2" />
ParentPage.aspx.cs
public partial class ParentPage : Page
{
public Control1 getControl1()
{
return ctrl1;
}
public Control2 getControl2()
{
return ctrl2;
}
}
In the user control you could do the following:
Control1.ascx.cs
public partial class Control1 : UserControl
{
public void Page_Load(...)
{
ParentPage myPage = (ParentPage)this.Parent;
Control2 ctrl2 = myPage.getControl2();
}
}
Hope you understand this. Else post your questions here, when I get to a computer w/ VS, should be a lot easier!
[Edit] While answering this I assumed that you are referring to a web page. This wouldn't be the same for a win forms app (just now i noticed you have said "window" and not "page" and that this is the C# forum and not the ASP.Net forum). But the idea would be similar - instead of page, you would be getting the Form's instance (the parent) which exposes 2 methods to return the user control id's, thereby enabling you to call that control's methods.
Cheers,
Karthik
modified on Thursday, October 21, 2010 11:01 PM
|
|
|
|
|
There are 2 things user control A needs to do:
- Get a reference to user control B (assume it's named
ctrlB and is of type CtrlB ).
- Call the appropriate method (assume it's named
DoSomething() ).
Control ctrlB = this.Parent.Controls.FirstOrDefault (p => p.Name.Equals ("ctrlB"));
Debug.Assert (ctrlB != null);
((CtrlB) ctrlB).DoSomething();
/ravi
|
|
|
|
|
Not sure about why you want to do someting like this, becouse this way your user control A will depend too much on your user control B and vice versa. I guess you should better place an event into your user control A, and make your user control B subscribe to this event.
|
|
|
|
|
I have found a way to do it now but the reason for doing it is because UC A is a custom treeview where an item can be selected and once selected it populates UC B which is a form containing text fields.
|
|
|
|
|
Ok, then I think the best way to go in this case would be subscribing the form to the AfterSelect event (I guess you have inherited the TreeView control) and call the method on your B control whithin this handler.
I am telling you this becouse this way you will be able to reuse your custom treeView in other future projects where, maybe, you might need to populate a different set of controls with some different information.
|
|
|
|
|
Hello guys,
I have an app made that worked with the old Google Keywords Tool External. It worked perfectly until a few days ago when they dropped the new interface. Now I can't seem to crack this myself, and I need some help.
Using opera dragonfly (helps debug http requests) I managed to see how everything looks "in the background" but I don't understand a thing now. With the old site,everything was crystal clear, but now it's not.
The new website is located here:https://adwords.google.com/o/Targeting/Explorer?__u=1000000000&__c=1000000000&ideaRequestType=KEYWORD_IDEAS#search.none
When you want to get keyword results (enter a keyword and press enter), google makes a POST request here:
https://adwords.google.com/o/Targeting/g?__u=1000000000&__c=1000000000
The request headers are:
Host adwords.google.com
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.11) Gecko/20101012 Firefox/3.6.11
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*
Now I don't understand what X-GWT-Permutation is (anx all the other x-gwt). I know it's google web toolkit ... but how the hell can I make a "call"to this website from c# .net (using httprequest) ?
The post content sent is:
6|1|69|https:
How should I send this? Like "uploading" a file? It's not a normal http post, because it has no variables, it's a simple text that it's sent.
So to make things short, I want to "download" the google keyword tool external page, and get the results in C# .net so I can process them.
Can anybody help?
Thanks in advance,
Vlad
|
|
|
|
|
Hi,
I'm not familiar with the Google interfaces, however I managed to do some other POSTs a few weeks ago, and basically this page[^] was all I needed.
sodevrom wrote: It's not a normal http post, because it has no variables, it's a simple text that it's sent.
It doesn't matter what the post data is, just write it to the stream, then proceed with accepting the result using HttpWebRequest.GetResponse() and HttpWebResponse.GetResponseStream() .
So if it worked for you earlier, there should not be a major problem (unless you want to understand what it is you are posting).
|
|
|
|
|
Hello,
I know how to use the httpwebrequest/response I am not really a "noob" in programming.
Now I decided to take a totally different approach, and get the text that I need by using a WebBrowser control. This is the best way to go I think, because it takes care of all the problems.
I have only one issue. For example to complete a field I use this:
HtmlElement username = this.wb.Document.All["username"];
username.SetAttribute("value", "aaaaa");
But how do I get the entire text of the webbrowser? It seems that if I use webBrowser1.DocumentText , it does not retrieve all the HTML code (it does not return everything that is visible). I think the problem is with dynamic code (javascript)
How do I get everything?
Thanks,
Vlad
|
|
|
|
|
Vlad,
you should receive the KeywordsTool data (keywords, CPC etc) using such code:
CComQIPtr<IHTMLElement, &IID_IHTMLElement> pBody;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IDispatch> pDisp = NULL;
CHECKPTR(pDisp = objExplorer.get_Document());
CHECKPTR(pDoc2 = pDisp);
HRESULT hr;
hr = pDoc2->get_body( &pBody);
BSTR BSTR_Page = NULL;
if (pBody){
hr = pBody->get_innerHTML( &BSTR_Page );
}
/
if (BSTR_Page){
sPage= (LPWSTR) BSTR_Page;
SysFreeString(BSTR_Page);
}
|
|
|
|
|
to set certain HTML elements in the page, you could iterate through the page element collection and check for the class name / id etc you need.
Note after DISPID_DOCUMENTCOMPLETE the KeywordTool's JavaScript starts to amend the document. So you would need to poll the page content every X milliseconds to check if the elements you require have been created.
VariantInit(&index);
V_VT(&index) = VT_I2;
V_I2(&index) = 0;
CComPtr<IHTMLElementCollection> pEltColl = NULL;
CComPtr<IDispatch> pEltDisp = NULL;
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> pDoc2;
CComPtr<IDispatch> pDisp = NULL;
CHECKPTR(pDisp = objExplorer.get_Document());
CHECKPTR(pDoc2 = pDisp);
HRESULT hResult,hr;
hResult = pDoc2->get_all(&pEltColl);
if (SUCCEEDED(hResult) && pEltColl)
{
// Search by value (manual search with a loop on all HTML Elements in document - could be long!)
long intElements = 0;
pEltColl->get_length(&intElements);
for (int intElement = 0; intElement < intElements; intElement++)
{
CComPtr<IDispatch> pCurrentDispatch = NULL;
VARIANT vElementIndex;
VariantInit(&vElementIndex);
V_VT(&vElementIndex) = VT_I4;
V_I4(&vElementIndex) = intElement;
hResult = pEltColl->item(vElementIndex, index, &pCurrentDispatch);
if (SUCCEEDED(hResult)) {
CComQIPtr<IHTMLElement, &IID_IHTMLElement> pCur_Element = pCurrentDispatch;
|
|
|
|
|
Last time I used an event handler was to detect when a given track that is being played by the media element had ended, which was not difficult simply because the media element has an event called media ended. (http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.mediaended.aspx[^])
However what if the class your working with don't have events, I am working with the socket class and would like to set an event handler to listen for any incoming connection. So for as you can see from the code below I am using a button click event to trigger the application to begin listneing, which isn't that I want. I would like the application to start listening for in coming connections from the get go. How to I do this:
private void BtnListen_Click(object sender, RoutedEventArgs e)
{
Socket listener = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
listener.Bind(new IPEndPoint(IPAddress.Any, 2112));
listener.Listen(10);
while (true)
{
Socket socket = listener.Accept();
string receivedValue = string.Empty;
byte[] receivedBytes = new byte[1024];
int numBytes = socket.Receive(receivedBytes);
receivedValue = Encoding.ASCII.GetString(receivedBytes,
0, numBytes);
if (receivedValue.Length < -1)
{
break;
}
else
{
MessageBox.Show(receivedValue);
break;
}
listener.Shutdown(SocketShutdown.Both);
listener.Close();
}
listener.Close();
Another problem I am having is that once the listen button is clicked, the application freezes until it receives something.
}
|
|
|
|
|
Look at Socket.BeginReceive (MSDN)[^] It should solve both problems if you read the documentation.
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|