|
Nope. It's just you.
|
|
|
|
|
|
Hi, this a ContextMenuStrip control; the 'RenderMode is set to 'ManagerRenderMode.
thanks, Bill
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
|
Hi, I'd check this out on another computer, if I had another one in use right now. Will post a screen shot soonish. thanks, Bill
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
I get this error message 'Access to the path 'F:\System Volume Information' is denied.' when I run the code below this text.
How can I ignore 'System Volume Information'?
string[] originalFiles = Directory.GetFiles(sourceFolder, "*", SearchOption.AllDirectories);
Array.ForEach(originalFiles, (originalFileLocation) =>
{
FileInfo originalFile = new FileInfo(originalFileLocation);
FileInfo destFile = new FileInfo(originalFileLocation.Replace(sourceFolder, destiniationFolder);
if (destFile.Exists)
{
if (originalFile.Length > destFile.Length)
{
originalFile.CopyTo(destFile.FullName, true);
}
else
{
Directory.CreateDirectory(destFile.DirectoryName);
originalFile.CopyTo(destFile.FullName, false);
}
});
|
|
|
|
|
Add an exception handler to catch that specific exception, like e.g.;
catch (System.UnauthorizedAccessException uax)
{
if (uax.Message.Contains("$Recycle.Bin"))
{
}
}
Also, use a REAL for-each loop so you can continue if you want to skip an item. object.ForEach has its uses, but it is not a replacement for a normal readable loop.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
exception handler does not work. And I don't know how to use object.ForEach.
I have also tried to use LINQ like this but it does work.
string[] originalFiles = Directory.GetFiles(sourceFolder, "*", SearchOption.AllDirectories).Where(f => !f.Contains("System Volume Information").ToString())
Is it possible in this case to use LINQ?
|
|
|
|
|
Member 14055879 wrote: exception handler does not work. It does; since "does not work" can mean anything, I tested it. The framework throws an exception as soon as GetFiles() fails. Meaning that if you try to "GetFiles" on something you don't have access to, it will throw an exception and not return any results.
Member 14055879 wrote: And I don't know how to use object.ForEach. You are already using that; there's a simpeler foreach loop that is almost always more appropriate.
Member 14055879 wrote: Is it possible in this case to use LINQ? No, since the exception will throw in the same place (Directory.GetFiles), and it wouldn't return a result. So filtering that result will still yield nothing.
Simple solution; write your own GetFiles that skips those and that returns the rest as the result. Code below been tested on my machine. Do remember that getting all files and folders from a drive will take "some time" - this might best be done from a separate thread, updating the UI as items are returned.
public Form1()
{
InitializeComponent();
string[] originalFiles = GetNonSystemFiles(@"C:\");
foreach (string originalFileLocation in originalFiles)
{
}
}
string[] GetNonSystemFiles(string path)
{
DirectoryInfo di = new DirectoryInfo(path);
List<string> result = new List<string>();
IEnumerable<DirectoryInfo> folders = null;
try
{
folders = di.EnumerateDirectories("*", SearchOption.TopDirectoryOnly);
}
catch (System.UnauthorizedAccessException uax)
{
System.Diagnostics.Debug.WriteLine("Unauthorized folder for: {0}, ex: {1}", di.Name, uax.Message);
}
if (null != folders)
foreach (DirectoryInfo folder in folders)
{
result.Add(folder.FullName);
if ((folder.Attributes & FileAttributes.System) != FileAttributes.System
&& (folder.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
result.AddRange(GetNonSystemFiles(folder.FullName).ToList());
}
IEnumerable<FileInfo> fileInfos = null;
try
{
fileInfos = di.EnumerateFiles("*", SearchOption.TopDirectoryOnly);
}
catch (UnauthorizedAccessException uax)
{
System.Diagnostics.Debug.WriteLine("Unauthorized file for: {0}, ex: {1}", di.Name, uax.Message);
}
if (fileInfos != null)
foreach (FileInfo fileInfo in fileInfos)
{
result.Add(fileInfo.FullName);
}
return result.ToArray();
}
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.
|
|
|
|
|
You can NOT use SearchOption.AllDirectories. It WILL fail when that search tries to get into folders the user has no access to.
LINQ will not help you get past this problem.
You have to write the code to traverse the directory tree yourself, wrapping the code inside the loop in a try/catch blockto handle the case of a folder not letting the user into it, and get the files in each folder separately.
It would also seem you need to read [^] because you apparently don't know the normal foreach statement even exists.
|
|
|
|
|
As you see in this (working) code excerpt:
if (usedates && d1 != null && d2 != null)
{
qstring.Append($"{dt1}{d1.Value}{dt2}{d2.Value}#");
}
I'm using predefined string constants (dt1, dt2), and parameters (nullable DateTime) passed in (d1, d2).
The thought occurred to me this is a lot like what produces the vulnerability to sql injection. But, perhaps this is comparing apples, and oranges ? After all, there's no equivalent to Commands in the very limited 'RowFilter ops.
p.s. I had to spend a ridiculous amount of time to figure out 'RowFilter syntax: maybe it's me ?
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
The documentation of the syntax is not the best, and it's only on the DataColumn.Expression page:
DataColumn.Expression Property (System.Data) | Microsoft Docs[^]
As far as I'm aware, the filter never goes anywhere near the database; it's only executed locally. And as you say, the syntax doesn't allow for data modification, so the worst that could happen is you'd see the wrong data in the resulting DataView .
Obviously if you're relying on the view to filter out data that the current user shouldn't be allowed to see, that could still be a problem. But that would be a data-disclosure vulnerability, rather than a data-modification vulnerability.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
A filter would only reduce the amount of data, so I see no risk of disclosure at all. Unless the filter itself is buggy of course, or the data is "drowning the fish" (not sure that means in English what it means over here: hide embarrassing info with a pile of data on top of it).
|
|
|
|
|
The risk would be if the filter could be manipulated to include additional records in the view - for example, by adding something like OR 1 = 1 to the end.
(I suspect "bury the lead" / "lede" would be the English equivalent of "drowning the fish".)
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
thanks ! that's an interesting idiom, Luc; in Thai there's an idiom "a fish drowned in the river," which kind-of refers to a person who is ruined by their own non-righteous actions; I am sure there may be many other subtle "resonances" of this with Theravadan Buddhist, and, other cultural memes/tropes ... that I am not aware of.
if i interpret your idiom as some form of "cover-up," then nothing could be further from the Thai modal behaviors that embody the paragon virtue of always disguising the "real issues" to avoid giving offense, or losing face ... always with a smile ...
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
Unfortunately "drowning the fish" is a widespread practice among a number of our politicians, either in legislation or in budget matters. It is small print without a change in font size...
|
|
|
|
|
thanks !
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
With SQL injection vulnerabilities, manipulated strings are injected. In your example, you use DateTime? variables on which .ToString( ) is called. For SQL injection to work, that ToString() call must result in some "bad" result like '; DROP TABLE STUDENTS; - that's not possible.
On the other hand, if your input are arbitrary plain strings, the user could inject such bad strings. But if, as others pointed out, the query is not sent to the database, only executed locally, also that does not matter anymore.
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
|
|
|
|
|
thank you, Bernard !
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali
|
|
|
|
|
I want to convert EventArgs type to PaintEventArgs type, cast button_click to form_paint, how do I write code ? You see my error code
namespace DrawText_Random
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
progressBar1.Minimum = 0;
progressBar1.Maximum = 100;
this.Paint += new System.Windows.Forms.PaintEventHandler(this.Form9_Paint);
}
int valueforShadowedTextPaint = 0;
private void btnDrawText_Click(object sender, EventArgs e)
{
progressBar1.Value = 0;
this.timer1.Interval = 100;
this.timer1.Enabled = true;
}
private void ShadowedTextPaint(PaintEventArgs e, int num)
{
Font fnt = new Font("Calibri", 296, FontStyle.Bold | FontStyle.Italic, GraphicsUnit.Point);
Graphics g = e.Graphics;
g.DrawString(num.ToString(), fnt, Brushes.DarkGray, 244, 104);
g.DrawString(num.ToString(), fnt, Brushes.Aqua, 240, 100);
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value < 100)
{
PaintEventArgs g = (PaintEventArgs)e;
Random rd = new Random();
Random rd = new Random();
int Number = rd.Next(0, 999);
ShadowedTextPaint(e, Number);
progressBar1.Value++;
}
else
{
this.Invalidate();
this.timer1.Enabled = false;
}
}
}
}
|
|
|
|
|
No, you can't.
Think about it this way: You have a car, and it's a Ford Fiesta. You take a badge off a Ferrari, and glue it on in place of the Ford oval badge. Does your car now do 200 mph and go round corners really well? Is it suddenly worth £100,000?
Of course not - and you are trying to do much the same thing with your code.
When you derive a class B from class A, B gets everything that is in A : field, properties, methods, events. But you have added things to B - other fields, other methods, other properties, and these do not exist in A. If you could cast an instance of A to an instance of B what would happen when you tried to use the new properties and methods? They don't exist in the original, so any information you tried to use would be "in limbo" and your app would crash because the system can't just "invent" the missing data!
Instead, you can create a new PaintEventArgs, and supply that with a new Graphics context to draw on then pass the new instance to your ShadowedTextPaint method instead - remembering to dispose of the Graphics context when you are finished with it. You can get the context with the Control.CreateGraphics Method[^]
But me? I'd pass just the Graphics context instead of a whole "dummy" PaintEventArgs - it's the only bit you need, anyway!
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
I understand you say, I mean how to remove the Form2_Paint method and you understand I say, you instructed me to use the new class by declaring Graphics g = this.CreateGraphics(), after creating a new class My program has run, but I have a problem with random numbers that it overwrites continuously on the screen, I want to draw a new number, I have to restore the screen before drawing, do you have any way ? My program corrects the code as follows:
...
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value < 100)
{
...
ShadowedTextPaint(Number);
...
}
else
{
...
}
}
private void ShadowedTextPaint(int num)
{
...
Graphics g = this.CreateGraphics();
...
}
...
|
|
|
|
|
First off, as I mentioned, if you create a Graphics object, you are responsible for Disposing it - or you app (and possibly the whole of Windows) will crash when it runs out of a very limited resource!
The best way to handle that is to use a using block:
private void ShadowedTextPaint(int num)
{
...
using (Graphics g = this.CreateGraphics())
{
...
}
} And the system will Dispose the Graphics when it goes out of scope.
But ... why are you messing about with this?
Add a Panel or similar control to your form as a place to write your number, and in yoru Tick event handler just call Invalidate on the Panel. Add a Panel.Paint event handler and draw your text on the panel in that using the Graphics object it supplies. That way, it all fits neatly into the "normal processing" of the form, and you don't have to mess about so much - or worry about everything else that is going on.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
modified 18-Oct-19 5:28am.
|
|
|
|
|
I am just beginning to learn about graphical functions, I do not know much about them, so I will listen and absorb your comments on the forum. I want to write a sequential random number jump program that uses graphical functions, if I use the Form1_Paint method it doesn't allow the random number jump continuously at will because my timer uses timer1_Tick, Currently I have not thought of how to use the Form1_Paint method to jump random numbers continuously, according to your instructions I will use the using (...) {...} block to write the program, I have used using block already but do not know how to prevent overwriting, you see the image file is overwritten, do you have any way ?
http://www.mediafire.com/view/behinj51ttc7ak5/ShadowTextRandom01.jpg/file
http://www.mediafire.com/view/0u5gqhymhxp6ygb/ShadowTextRandom02.jpg/file
|
|
|
|
|