943,587 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 2306
  • C# RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Dec 1st, 2008
1

Re: combining methods

are you meaning something like this?

C# Syntax (Toggle Plain Text)
  1. foreach (HtmlElement link in webBrowser1.Document.Links)
  2. {
  3. bool isValid = false;
  4. string linkItem = link.GetAttribute("HREF").ToString();
  5.  
  6. Uri urlCheck = new Uri(linkItem);
  7. WebRequest request = WebRequest.Create(urlCheck);
  8. request.Timeout = 10000; // 10 seconds
  9.  
  10.  
  11. WebResponse response;
  12. try
  13. {
  14. response = request.GetResponse();
  15. isValid = true;
  16. Console.WriteLine("Good");
  17. }
  18. catch (Exception)
  19. {
  20. Console.WriteLine("Bad"); //url does not exist
  21. }
  22.  
  23. if(isValid)
  24. {
  25. listViewLinks.Items.Add(link.GetAttribute("HREF").ToString());
  26. }
  27. }
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Dec 1st, 2008
0

Re: combining methods

Yeah, that's pretty much what I was meaning. Appears I had that at one time, just not at the same time! That code seems to work, but when I click the "Check Links!" button, I just get "A first chance exception of type 'System.Net.WebException' occurred in System.dll" for the links. I know that the links are good. Sometimes it also says "Bad" also.
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008
Dec 1st, 2008
0

Re: combining methods

what are the href's coming in as?

also capitalization

if it also says bad, then the exception didn't occur in that place, what are links coming in as, and what are they being resolved as?
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Dec 1st, 2008
0

Re: combining methods

In my first code, the links showed up in my listView as "http://www.webpage.com/." Now nothing is showing up in my box. I don't know if that is because it is waiting for it to check all the sites or what. It returned back "Good" on the very first link on the page, which also has the same url as the page that I was checking the links on, but it still didn't show up in my listView. Now every link, every 10 seconds is gives me "Bad", then "A first chance exception of type 'System.Net.WebException' occurred in System.dll" at the same time.
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008
Dec 1st, 2008
0

Re: combining methods

i don't know about that trailing / with the .

what is the details on the exception?

try like this
http://msdn.microsoft.com/en-us/library/debx8sh9.aspx
Last edited by dickersonka; Dec 1st, 2008 at 11:46 pm.
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Dec 1st, 2008
0

Re: combining methods

It doesn't leave the trailing / after the aspx, html, php, or anything else. I tried to check the links on microsoft.com and got an unhandled exceptions error. It said something about their being a wrong uri prefix here WebRequest request = WebRequest.Create(urlCheck); . I also tried adding an extra / and even a /r/n to the link, but it didn't make any difference.
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008
Dec 2nd, 2008
0

Re: combining methods

try with httpresponse and httprequest
Reputation Points: 133
Solved Threads: 141
Veteran Poster
dickersonka is offline Offline
1,162 posts
since Aug 2008
Dec 2nd, 2008
0

Re: combining methods

Tried it, no difference. I changed it back and now I'm getting alot more "Good" links. I still get alot of "first chance exceptions" though.
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008
Dec 2nd, 2008
0

Re: combining methods

What does the exception say?
Have you allowed for redirection? Eg if you went to www.somesite.com chances are http is telling "hi thats nice for you, now ask for say index.html"
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 2nd, 2008
0

Re: combining methods

Here is the exception detail.
C# Syntax (Toggle Plain Text)
  1. System.NotSupportedException was unhandled
  2. Message="The URI prefix is not recognized."
  3. Source="System"
  4. StackTrace:
  5. at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
  6. at System.Net.WebRequest.Create(Uri requestUri)
  7. at linkchecker.Form1.toolStripButtonLinks_Click(Object sender, EventArgs e) in C:\Documents and Settings\sfrider0\My Documents\Visual Studio 2005\Projects\linkchecker\linkchecker\Form1.cs:line 73
  8. at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
  9. at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
  10. at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
  11. at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
  12. at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
  13. at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
  14. at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
  15. at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
  16. at System.Windows.Forms.Control.WndProc(Message& m)
  17. at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
  18. at System.Windows.Forms.ToolStrip.WndProc(Message& m)
  19. at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
  20. at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
  21. at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
  22. at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
  23. at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
  24. at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
  25. at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
  26. at System.Windows.Forms.Application.Run(Form mainForm)
  27. at linkchecker.Program.Main() in C:\Documents and Settings\sfrider0\My Documents\Visual Studio 2005\Projects\linkchecker\linkchecker\Program.cs:line 17
  28. at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
  29. at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
  30. at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
  31. at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
  32. at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
  33. at System.Threading.ThreadHelper.ThreadStart()
This is line 73.
C# Syntax (Toggle Plain Text)
  1. WebRequest Request = HttpWebRequest.Create(urlCheck);
Last edited by sfrider0; Dec 2nd, 2008 at 11:22 pm.
Reputation Points: 16
Solved Threads: 0
Junior Poster
sfrider0 is offline Offline
149 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Communicating Data Between Forms
Next Thread in C# Forum Timeline: exception pleasehelp





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC