|
Thanks here is the final code it works perfectly...
bool IsValidFilename(String ^fileName)
{
if ( String::IsNullOrEmpty( fileName ) == true )
return false;
array<Char>^ invalidFileChar = System::IO::Path::GetInvalidFileNameChars();
for each ( Char ^i in invalidFileChar )
{
if ( fileName->Contains(String::Format("{0}", i)) )
{
String ^tmp = String::Format(L" '{0}' is invalid in a file name.\n", i);
System::Windows::Forms::MessageBox::Show(gcnew String(tmp),gcnew String(L"Warning"),
MessageBoxButtons::OK);
return false;
}
}
return true;
}
Programmer
Glenn Earl Graham
Austin, TX
|
|
|
|
|
That doesn't look like C# to me.
|
|
|
|
|
String.IndexOfAny() seems appropriate here.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
I'd just try it and catch the exception if any.
Let the OS/framework determine validity; it knows best.
|
|
|
|
|
But if its speed you want, catching the exception may not be the best solution.
Phil
|
|
|
|
|
Absolutely, why check what the OS/framework will check anyway? That's wasteful.
The custom check may be faulty, causing a false valid or invalid. A false valid will likely result in an exception anyway, so you've wasted the time on the extra check, plus the time writing the faulty check.
I know I couldn't write a filename validity checking routine as fast and accurate as the built-in one.
You don't know to what OSs the framework may be ported in future (I know, it's unlikely) and what their validity rules are.
I could certainly see adding some additional checking, like ensuring the name doesn't include a SPACE, or is 8.3 or something, but other than that you're just wasting your time.
This is a wheel best not reinvented.
|
|
|
|
|
Or a Regular Expression, matching any of the invalid characters.
|
|
|
|
|
I like that idea. A regex over a path size string should be blindingly fast as well.
"Once in Africa I lost the corkscrew and we were forced to live off food and water for weeks." - Ernest Hemingway
My New Blog
|
|
|
|
|
Hi All,
Is there any control/method/class/namespace available that i can use in my code in order to get windows XP like left menu.
Thank you!
"Mess with the Best, Die like the rest"
|
|
|
|
|
|
That was very helpful.
Thank You!
"Mess with the Best, Die like the rest"
|
|
|
|
|
Hi..
I have a web application(ASP.NET 2.0, C#), in which I am exporting a xml file.
The web page has a button called Export. When the user clicks the Export button, the File Download pops up, in which it has the Open,Save and Cancel Butons as in a normal file download pop-up. Being an xml file, the page also opens up,without the content behind the File download pop-up,
When the user clicks Cancel button, the file download pop up is gone, but the xml page(without the contents) is still open. This also happens when the user has successfully downloaded the xml file(Xml page is open)
Is it possible to close the xml page after the user clicks the cancel button and after the user saves the xml file? I am using Internet Explorer 6, Windows xp, SP1.
Please help.. Thanks
Thanks & Regards,
Venkat
|
|
|
|
|
i want to create a shape Control like that you got here. But his Control can t draw antialiased linies =/
How can i draw smooth linies ?
|
|
|
|
|
If I recall theres some settings on the Graphics object that can help you out. Anti-aliasing is more of a quality setting on the Graphics object, than specifically asking for the thing you are drawing to be smoothed.
|
|
|
|
|
Yea i use this already but it looks not really Antialiased =/
the edges of a pie, for example, looks fuzzy but not smoothed
I have a Custom Control wich inherits from the Control class and my paint code looks like this
protected override void OnPaint( PaintEventArgs e ) {
base.OnPaint( e );
if( ( this.Width <= 0 ) || ( this.Height <= 0 ) ) return;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
GraphicsPath path = createGraphicPath( Shapes.Pie);
this.Region = new Region( path );
Pen pen = new Pen( new SolidBrush( borderColor_ ), borderWidth_ );
pen.DashStyle = borderStyle_;
e.Graphics.DrawPath( pen, path );
path.Dispose();
pen.Dispose();
}
|
|
|
|
|
Runtime error on accessing "role" from App.config file.
Any idea how to fix the problem?
Code:
string str = System.Configuration.ConfigurationManager.AppSettings["role"];
App.config:
<configuration>
<appsettings>
<add key="role" value="Easy">
<policyinjection>
<policies>
<add name="Policy">
Thanks
|
|
|
|
|
You will need to re-post since you forgot to check the "Ignore HTML tags in this message" check box. So we can't see your app.config or your error message.
Thanks,
Ben
|
|
|
|
|
Oops but i figured out the problem. Thanks anyway.
|
|
|
|
|
I need WinForms function which displays modal window with text given as parameter and returns value entered by user or null if esc pressed.
Where to find some source code for this ?
Andrus
|
|
|
|
|
Form f = new Form();
f.ShowDialog();
myValue = f.formValue.ToString();
If you look at the above, create a new form replacing the "Form" with the name of your form.
Show the form with a ShowDialog() will prevent any other part of your app from showing till the form is closed.
Then access a public variable or accessor of your form to set a local variable to the value the user entered.
Hope this helps you.
Hogan
|
|
|
|
|
Hi
How to insert string value and Button in Datagridview cell.
Like properties window in visual studio 2005.
In our project, their is a module which shows same like Properties windows in visualstudio 2005. so that we use datagridview and using DataGridViewComboBoxCell to insert combo box in some particular cell.
our problem is suppose if we insert a filename, so that we need textbox and same with small button which will used to browse the file.
so that how to insert usercontrol or textbox with button in datagridview cell?
|
|
|
|
|
i didn't work a lot With DataGridView, adding userControl to DataGridView can be done but in the cell I don't know
you can inherit from DataGridViewTextBoxCell class and override the Paint method for resizing the TextBox (i said form TextBoxCell because creating a TextBox is far more harder than a Button) and for drawing a button beside the textBox.
I know this is a tedious solution but it would work!
|
|
|
|
|
Thanks Hessam Jalali, yet to try this, can you explain little bit briefly.
|
|
|
|
|
I need to add row in DatagridView based on array of business entities.
I'm using NHibernate.
NHiberante returns array of business objects.
So my source type is System.Array and I cannot change it.
Joe Stegman "DataBinding FAQ - Updated.doc" describes that BindingList<t>
AddingNew event should be used in this case.
Also there is CoreAddNew method which is not documented in VCS 2005 Express
documentation.
I expect that BindingList<t> or some of its implementation can maintain
separate list of added objects by implementing custom Add() method.
How to fix ?
Andrus.
Using .NET 2.
Code to reproduce:
using System.Windows.Forms;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
<br />
class TestApplication {<br />
static void Main() { Application.Run(new TestForm()); }<br />
}<br />
<br />
class TestForm : Form {<br />
<br />
DataGridView DataGridView = new DataGridView();<br />
<br />
public TestForm() {<br />
Controls.Add(DataGridView);<br />
<br />
BindingSource BindingSource = new BindingSource();<br />
IList<Customer> list = new Customer[0];<br />
BindingList<Customer> bindingList = new BindingList<Customer>(list);<br />
BindingSource.DataSource = bindingList;<br />
<br />
BindingSource.AddingNew += delegate(object sender, AddingNewEventArgs e) {<br />
e.NewObject = new Customer();<br />
};<br />
<br />
DataGridView.DataSource = BindingSource;<br />
}<br />
}<br />
<br />
class Customer {<br />
string name;<br />
public string Name {<br />
get { return name; }<br />
set { name = value; }<br />
}<br />
}
Observed:
System.NotSupportedException was unhandled
Message="Collection is read-only."
Source="mscorlib"
StackTrace:
at System.ThrowHelper.ThrowNotSupportedException(ExceptionResource
resource)
at
System.Collections.ObjectModel.Collection`1.System.Collections.IList.Add(Object
value)
at System.Windows.Forms.BindingSource.Add(Object value)
at System.Windows.Forms.BindingSource.AddNew()
at System.Windows.Forms.CurrencyManager.AddNew()
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.AddNew()
at
System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnNewRowNeeded()
at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell&
dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean
canCreateNewRow, Boolean validationFailureOccurred)
at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32
columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean
validateCurrentCell, Boolean throughMouseClick)
at
System.Windows.Forms.DataGridView.SetAndSelectCurrentCellAddress(Int32
columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean
validateCurrentCell, Boolean throughMouseClick, Boolean clearSelection,
Boolean forceCurrentCellSelection)
at
System.Windows.Forms.DataGridView.MakeFirstDisplayedCellCurrentCell(Boolean
includeNewRow)
at System.Windows.Forms.DataGridView.OnEnter(EventArgs e)
at System.Windows.Forms.Control.NotifyEnter()
at System.Windows.Forms.ContainerControl.UpdateFocusedControl()
at
System.Windows.Forms.ContainerControl.AssignActiveControlInternal(Control
value)
at
System.Windows.Forms.ContainerControl.ActivateControlInternal(Control
control, Boolean originator)
at
System.Windows.Forms.ContainerControl.SetActiveControlInternal(Control
value)
at System.Windows.Forms.ContainerControl.SetActiveControl(Control
ctl)
at System.Windows.Forms.ContainerControl.set_ActiveControl(Control
value)
at System.Windows.Forms.Control.Select(Boolean directed, Boolean
forward)
at System.Windows.Forms.Control.SelectNextControl(Control ctl,
Boolean forward, Boolean tabStopOnly, Boolean nested, Boolean wrap)
at System.Windows.Forms.Control.SelectNextControlInternal(Control
ctl, Boolean forward, Boolean tabStopOnly, Boolean nested, Boolean wrap)
at System.Windows.Forms.Form.set_Active(Boolean value)
at System.Windows.Forms.Form.WmActivate(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 TestApplication.Main() in C:\test\test\Program.cs:line 20
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()
*/
Andrus
|
|
|
|
|
Good evening!
I would like to add OnClick-events to all button-controls within a form which contains a single split-container. I'll try to explain it:
I have a Windows form which includes one control, a spli-container, which itself has two panels. In one of these there are several buttons. All of them should subscribe to a click-event during initialization process.
I tried it with
[code]
foreach (Control in this.Controls)
{
if (cntr is Button)
{cntr.Click += new EventHandler(delegate(object sender, EventArgs e) {MessageBox.Show(cntr.Name);});}
}
[/code]
but "this.Controls" contains only the split-container.
I know that in this very special example I could as well enumerate through the panels of the split-container, but I would like to use a solution which is independent of the amount of the panels.
I think a possibility is needed, which allows to check if a control contains sub-controls and if so, one of these is a button type control.
Help would be appriciated!
|
|
|
|