|
This isn't really something I need help on, but more wondering why or which way is better from asking experienced programmers.
Request.QueryString["..."];
or
Request.QueryString.Get("....");
Is there a reason for both of them? Does using the .Get save it time from not having to realize it needs to "Get" the query string? Just a silly question that has been bugging me so I've decided to ask.
|
|
|
|
|
There is no difference. The Item property get method (that you use in the first case) just calls the Get method.
The reason that both exists is probably to support programming languages that can not use an indexer (the first alternative).
Another alternative to get the values is the GetValues method, and that one is different. It returns the values as a string array instead of concatenating them together as a comma separated list.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Excellent. Thank you. Just something I've been wondering about. Thanks again!
|
|
|
|
|
Hii all..
I am creating a small application that supposed to monitor printing activities. I used Win32_PrintJob and successfully get the informations of printing process such as DocumentsName, PagesPrinted,TotalPages,Size,etc.
I store these values into database as printer log.
But, I have some difficulties in getting the bytes of printed files. Is it possible to do that using Win32_PrintJob?
I want to get these bytes to store it into database, so that the admin can see the content of printed files in the next time.
Thanks before for the answers.
|
|
|
|
|
I don't think there's an easy way to get the print job bytes using WMI. Try another, faster approach. Get every print queue using the LocalPrintServer.GetPrintQueues() method, iterate from 0 to the return value of the PrintQueue.NumberOfJobs property of the individual print queue, and use the returned PrintSystemJobInfo class from the PrintQueue.GetJob() method. There should be a PrintSystemJobInfo.JobStream property which will give you the stream of the job's data. All of these can be found in the System.Printing namespace, which you need to add a reference to (ignore what the MSDN page says about Vista, it works on XP just as well)
|
|
|
|
|
1 LocalPrintServer lps = new LocalPrintServer();
2 PrintQueueCollection pqc = lps.GetPrintQueues();
3 PrintSystemJobInfo pj;
4 foreach (PrintQueue pq in pqc)
5 {
6 pj = pq.GetJob(pq.NumberOfJobs);
7
8 }
As u sugggested, I create above code. But, I get an error at 6 line. With error description "Value cannot be null. Parameter name: printingHandler".
Do you have some suggestion? Or could you give me simple code that show your suggestion will work.
Thanks...
|
|
|
|
|
private PrintSystemJobInfo GetInfo()
{
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue q = LocalPrintServer.GetDefaultPrintQueue();
q.Refresh();
foreach (PrintSystemJobInfo pj in q.GetPrintJobInfoCollection())
{
return pj;
}
return null;
}
PrintSystemJobInfo pj = GetInfo();
int len = pj.JobStream.Length;
I use Windows XP Sp2
When executing len = pj.JobStream.Length an error occur "Object reference not set to an instance of an object."
Is JobStream works in XP? Because I read that it works on vista only.
|
|
|
|
|
If it only worked in Vista, then a different exception would have been thrown. As it is, you seem to be dropping past the foreach() for some reason. You do have something printing, even if only to a dummy printer, which isn't connected to the computer?
On the other point, I looked through the System.Printing.PrintQueue class with Reflector, and there doesn't seem to be any code which checks if you're running Vista, unless it relies on some new APIs, but I haven't seen any
|
|
|
|
|
I use both of connected printer and dummy printer. but the PrintSystemJobInfo.JobStream always return null . Any suggestion?
|
|
|
|
|
There is nothing which could cause the JobStream property to return null. Try something like this for the GetInfo() method of yours:
private PrintSystemJobInfo GetInfo()
{
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue q = LocalPrintServer.GetDefaultPrintQueue();
for(int i = 0; i < q.NumberOfJobs; i++)
{
return q.GetJob(i);
}
return null;
}
On the off chance, step through the code and check the NumberOfJobs property. Is it set to zero?
|
|
|
|
|
I've tried your code. When I executing the return q.GetJob(i);, it apprears error :
"An exception occurred while creating print job information. Check inner exception for details."
I search the inner exception, and found "Object reference not set to an instance of an object."
In my previous code:
private PrintSystemJobInfo GetInfo()
{
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue q = LocalPrintServer.GetDefaultPrintQueue();
q.Refresh();
foreach (PrintSystemJobInfo pj in q.GetPrintJobInfoCollection())
{
return pj;
}
return null;
}
PrintSystemJobInfo pj = GetInfo();
From pj I can get the printing information such as DocumentName and NumberOfPage. But when I try to get value from of JobStream, the error "Object reference not set to an instance of an object." apprears. Seems that the value of stream is null.
|
|
|
|
|
There's only one thing more that I can think of. Stick with your original GetInfo() and after you get the PrintSystemJobInfo returned by GetInfo(), call the Refresh() method before you access the JobStream property. Something like this:
PrintSystemJobInfo pj = GetInfo();
pj.Refresh();
Console.WriteLine(pj.JobStream == null);
If that doesn't work, then I don't know of any other method to do what you originally intended
|
|
|
|
|
Hi all
Now i finished My program, got it's EXE works.
is there is any way to get the code from EXE
and how to protect my EXE from this
Thank you..
|
|
|
|
|
mutafa81 wrote: is there is any way to get the code from EXE
Yes - you can disassemble the code.
mutafa81 wrote: and how to protect my EXE from this
You might want to try an obfuscator. It won't stop you getting the cod out, but it will make it bloody hard to read.
|
|
|
|
|
Pete O'Hanlon wrote: You might want to try an obfuscator. It won't stop you getting the cod out, but it will make it bloody hard to read.
I agree. Though I know of an obfuscator that can cause Reflector to crash when trying to disassemble the obfuscated code.
"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
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
That sort of thing isn't worth worrying about.
|
|
|
|
|
Nah, I don't agree.
While this might be true for most apps, it's surely not for all of them. It entirely depends upon what's inside your code (e.g. company-specific algorithms that are protected by law).
At least you have to know about the problem to be able to make an informed decision about it.
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
PIEBALDconsult wrote: That sort of thing isn't worth worrying about
Not if you have intellectual property that you do not want the competition to find, or a client to have some one dig around in your work and sell it to someone else.
"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
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
The big question is, why would someone want to read your code ? People who worry about that, usually have nothing to worry about.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: why would someone want to read your code ?
Spying among competing businesses could be one reason.
While most of the programs written won't need protection indeed, there might be some that do. It's in any way a good thing to know about the problem and its possible 'solutions'.
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
Perhaps, but in most cases, it's not needed. In fact, I've seen people who have ASP.NET sites ask this ( how does anyone get the dlls in that case ? )
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Christian Graus wrote: Perhaps, but in most cases, it's not needed.
I fully agree.
Christian Graus wrote: I've seen people who have ASP.NET sites ask this
This obviously doesn't make any sense at all.
These things happen when people do not know (or care) how it all works.
I just wanted to say: You have to be aware that there can be an issue.
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
mutafa81 wrote: is there is any way to get the code from EXE
Yes, this is easily done. The best and most popular tool for that is .NET Reflector[^].
mutafa81 wrote: and how to protect my EXE from this
There is no real escape. What you can do is use an obfuscator. These tools don't protect your code from being disassembled, but they make it as unreadable as possible.
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
Thomas Weller wrote: These tools don't protect your code from being disassembled, but they make it as unreadable as possible.
While that is true, I did find one such obfuscator that actually crashes Reflector. The obfuscator was relatively inexpensive compared to some of the others out there.
"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
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
You could always use .NET Reactor, it merges the application with native code.
It stops any decompiling according to the website.
A craft is an enemy if not well learned.
|
|
|
|