|
I think i have found a way to do it. Had a look at the code i would need to use to access the cache and it looked way too nasty.
So i constructed a simple function which searches recursively through all the directories in the cache, including the hidden ones, looking for files with the same name as the image i just downloaded in the webbrowser. It then takes the one with the most recent creation date and gives me the full path to it.
A simple and inelegant hack, but it works =).
Posted below if it can help anyone.
<br />
private void SearchCache(string filename) <br />
{<br />
string filetype = filename.Substring(filename.LastIndexOf('.')+1).ToLower();<br />
filename = filename.Substring(0, (filename.LastIndexOf('.')));<br />
<br />
DateTime nowDT = DateTime.Now;<br />
DateTime latestFileDT = new DateTime();<br />
string filePath = "";<br />
<br />
string cachePath = @"C:\Documents and Settings\[UserName]\Temporary Internet Files\Content.IE5";<br />
<br />
DirectoryInfo cacheDir = new DirectoryInfo(cachePath);<br />
<br />
string regexPattern = "^"+filename+@"\[?(\d+)*\]?."+filetype+"$";<br />
Regex r = new Regex(regexPattern, RegexOptions.IgnoreCase | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled);<br />
<br />
foreach (DirectoryInfo d in cacheDir.GetDirectories())<br />
{<br />
foreach(FileInfo f in d.GetFiles())<br />
{<br />
if (r.IsMatch(f.Name))<br />
{<br />
if (f.CreationTime > latestFileDT)<br />
{<br />
latestFileDT = f.CreationTime;<br />
filePath = f.FullName;<br />
}<br />
}<br />
}<br />
}<br />
}<br />
|
|
|
|
|
Hello everyone,
I am trying to learn the basics of databases but i found myself deep in an hole now:
System.InvalidCastException was unhandled
Message="Specified cast is not valid."
Source="System.Data"
StackTrace:
at System.Data.SqlClient.SqlBuffer.get_Int32()
at System.Data.SqlClient.SqlDataReader.GetInt32(Int32 i)
at Winner.Database.votos() in I:\Documents\Server\Winner\Winner\Database.cs:line 48
at Winner.Form1.Form1_Load(Object sender, EventArgs e) in I:\Documents\Server\Winner\Winner\Form1.cs:line 21
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Winner.Program.Main() in I:\Documents\Server\Winner\Winner\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
That is the exception i am getting trying to show all the data from a table in sql.
This is how i am doing it:
SqlCon = new SqlConnection(ConnString);
SqlCmd = new SqlCommand();
SqlCmd.CommandText = "Select * From party";
SqlCmd.Connection = SqlCon;
SqlCon.Open();
dataReader = SqlCmd.ExecuteReader();
int i = 0;
int temp = 0;
while ((dataReader != null) && dataReader.Read())
{
temp = dataReader.GetInt32(1);
Votos[i] = temp;
i++;
}
What am i doing wrong???
Thanks all in advance!
Luis E Tineo S
|
|
|
|
|
Do you realise that 1 is the second column ? Have you tried using the debugger to work out what the data type in that column is ? It's always better to specify the column names you want, then you'd also know their order for sure, and you'd know what the second column was.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
When a NullReferenceException is thrown in a complex method, is there any way to query the exception (or something in the Diagnostics namespace) to get the name of the object that caused the problem? By name, I mean the name I gave the object in the source code (even the type would be helpful in finding the little bugger).
I've centralized my exception reporting in the IDE I've written so that my clients can give me a lot of details about the environment at the time of the exception, but the one thing I need in these cases is the name of the blasted object that somehow got "nulled." If I understand correctly, .Net assemblies store all these symbols, so it should have access to this at runtime outside of Visual Studio. (BTW, I'm using VS2005.)
Anyway, I have the sense that this is a noob question, but I've looked all over and can't find a way to do this. (Other than put a lot of custom debugging code into my app which is not really practical now that it's deployed in the field.)
Also, I realize that finding this sort of thing is pretty straight forword in small, less complex methods, but I'm having issues tracking-down the fault in bigger methods, outside the IDE's debugger.
Your help (and patience) is much appreciated! !
modified on Sunday, December 09, 2007 5:50:34 PM
|
|
|
|
|
I don't think it's possible. My advice:
1 - break up big methods into smalle ones
2 - build logging in to your app, so you can add logging code for methods that crash on a client machine, and can just turn on logging in your config
3 - always log exceptions so you can track down errors.
4 - If you see more than one object that could be null, add checks for them all, they will all bite you at some point.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Christian, all good advice.
#1: Hmmm, I tend to keep my method size down to no more than a page already, but a method may involve many objects.
#2,#3: I'm already doing. I've got exceptions with centralized reporting bracketing most of my methods.
#4: Yeah, I may need to do this with specific assertion tests to go with the bracketing exception handler (which can't pinpoint the problem object). I've been layering my parameter validation, but apparently that's not sufficient.
It's disappointing that the CLR can't leverage the metadata at it's disposal to answer this silly, but crucial question.
|
|
|
|
|
Hi!
With debug builds you can at least get the line number and source file name where the exception occurrs, but you don't always have a name for the "thing" that evaluates to null.
For example, what should this "null object name" return in this case:
MyClass mc = new MyClass();
return (mc as AnotherClass).ToString();
A very simple and constructed case, but I think you can easily see that as soon as you combine two or more operations without assigning the result to a new variable every time, the runtime doesn't have a chance to give a name for the null object because it is not named explicitely.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Dear friends,
Please help me with the following:
In a C# program, how can I reuse a method that takes classes (or list of classes, List<classname> ) as arguments? The method is defined inside a class.
Presently, the method in my program works only if "the object of the function call" and "the object defined in the parameter list of the function" are the same. Thus practically I have to repeat the method code as many times as the function is called, each with a different class as argument.
The following shows the gravity of my situation: Supposing there are 10 such methods in my c# program and each method (which by itself is quite long and detailed) has to be performed on 10 different classes as arguments.
What I want is, the method (written as a single copy, meaning, if-else option is ruled out) should accept any suitable class passed to it, any number of times, and produce the result. I am looking for a suitable way, using for example, inheritance. Use of gettype to resolve the classname doesnot work as it produces complie errors.
Suppose if the method takes Int or Double argument types, this problem does not arise; thus, is this a fundamental problem in OOP languages? Is there a classical method (I mean, not workaround) to overcome this problem?
Anyway I would be happy to learn an efficient workaround too!
Thanks for ur replies in advance!
Greetings,
Karthik
|
|
|
|
|
karthikde1980 wrote: (which by itself is quite long and detailed)
Then it should probably be refactored. I aim for methods to never be > 30 lines if I can help it.
karthikde1980 wrote: thus, is this a fundamental problem in OOP languages?
No, oop has nothing to do with it, except that oop is the solution. You can either write a generic method ( which is not OOP, but lets you use any class you like ), or you can define a base class for all the classes you want to pass, and just write one method that passes that.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Indeed, one simple base class which the others are derived from. Now thats a feature i couldn't do without.
But remember, you can cast a derived class as its base class. But you cannot cast the base class, as one of its dervied classes.
My current favourite word is: Bauble!
-SK Genius
|
|
|
|
|
Well, you can only cast it if it was an instance of the derived class to start with. That stands to reason.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi,
how can I get size of a structure? There is sizeof too, but it doesn't work.
Thanks.
|
|
|
|
|
How is sizeof not working?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
daavena wrote: but it doesn't work.
That is vague. You have to tell us in what respect does it not work. Does it cause a compiler error? Does it cause an exception? Do you disagree with the result? What?
|
|
|
|
|
Hello All,
If I add certain Shapes (e.g. Polylines) to a WPF Grid (placed inside a WPF window), would they be rendered with hardware acceleration?
|
|
|
|
|
I know that you can actually write code that tells you if hardware acceleration is being used. I believe the answer is 'yes, if you have a good enough graphics card'
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You can use the "rendering tier" to get a feeling for the caps of the videocard:
<br />
int tier = (System.Media.Rendercapability.Tier >> 16);<br />
0 is bad - only software emulation
1 is ok - the card supports partial accel (DirectX 7 - DirectX 8)
2 is state of the art with full accel
|
|
|
|
|
Bartosz Bien wrote: would they be rendered with hardware acceleration?
I think they should. Not 100% certain though.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Hi everyone.
Does anyone know if it is possible to include the .net core assemblies, say in a cd for our program to use theme and solve the problem of detecting the installed .net version and installing the required version?!
It's a real problem for me that create multimedia cds using C#!
Sojaner!
|
|
|
|
|
I think there are .NET obfuscators that cram all the dependencies into one assembly and optionally compile it into a native executable.
ROFLOLMFAO
|
|
|
|
|
I could not find any free full functional one can you suggest me one please?!
Sojaner!
|
|
|
|
|
There are no "free full functional" ones.
The one or two products that promise to include all the required parts into your program are quite expensive from what I've heard.
But obviously, if one main requirement for your application is that no installation is required, then choosing .NET was a mistake in the first place.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
mav.northwind wrote: if one main requirement for your application is that no installation is required, then choosing .NET was a mistake in the first place.
Actually, it's not a mistake. If the OS comes with the required framework, no installation is required and a simple copy and paste is all that is needed. (e.g.: I can compile and send the resulting assembly over to my friend's computer for execution without him having to install anything.)
ROFLOLMFAO
|
|
|
|
|
Ri Qen-Sin wrote: If the OS comes with the required framework
I think that's exactly the problem he's facing.
Windows Server 2003 comes with .NET 2.0 pre-installed, Vista comes with .NET 3.0 pre-installed.
For all other OS's there is no .NET installed out-of-the-box, and without installing .NET the application doesn't work.
Installing .NET can be automated, but even then it takes a while.
Once the target system does have .NET, of course you can simply use XCOPY deployment for .NET applications, but without the framework you're grounded.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|