|
That just tells you that the file has been created, not that it's finished writing to disk.
|
|
|
|
|
Yes. This wont tell the OP if the file has been written correctly or not.
|
|
|
|
|
If you're trying to open the file as read-only, with all the options set correctly, you shouldn't have any trouble opening it right after you created it. If you want more access rights (such as write and delete) or didn't specify them, then some other process might be busy reading your file and thus preventing your general-purpose open operation. Such other processes could include file indexers, anti-virus software, etc.
Try using File.ReadAllText, ReadAllLines, ReadAllBytes for instance, they should always succeed as their name implies they only want to read.
|
|
|
|
|
Yes, you'll get an error. Something about the file being in use by another process, or whatnot.
So, use that. Try to open the file exclusive (no read/write sharing enabled). If it fails, wait a second or two and try again. You'll probably want to put this in a loop so you're not hard coding each retry. The loop will need a bailout value so you're not retrying forever. That value could be, say, 5 times, then return a failure to your calling code.
|
|
|
|
|
I have a project(WFA) in this project there is a need to find the numbers of folders and files with there name
love
|
|
|
|
|
|
Don't bother
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
Hello Code Project
I'm developing an app and i'm having some issues so i hope somebody helps me out
I have a "form" in that form i made a search to a table from a database named "Vehicle_Information"
So i filter the results through checkboxes example
◘ID
◘GPS ID
◘NAME
....
So when the user checks ◘ID, the column of "ID" appears on the Data Grid
i can create an excel file from a datagrid but when the data is created ALL THE COLUMNS AND DATA APPEARS ON THE EXCEL FILE! and i don't want that , i just want the columns the user selected.
My Question is: HOW CAN I SEND TO AN EXCEL FILE A GROUP OF SELECTED COLUMNS OF DATA FROM A DATAGRIDVIEW????
I've tryed so hard :/
Thanks.
|
|
|
|
|
|
Hey Excel object model is a very powerfull object in the .net family. You can easly select Which values to export usind the Range property of the class. For instance if you wanted to export say cell A1 to A12 you can set the Excel.Range("A1 A12") when exporting hope this helps
|
|
|
|
|
The thing is i'm not an expert on C#, and here's an image to show u how i want the program to function
You can notice the checkboxes so, if only check box of ID is cheked then when i click to EXPORT TO EXCEL only the column of ID will exported.
|
|
|
|
|
Which is better to retrieve IP address of PC
|
|
|
|
|
Try reading the documentation on them both.
GetHostEntry[^] - Resolves the specified host to an IPHostEntry object containing address information about the host.
GetHostName[^] - returns the host name of the local computer.
Only one of these returns any IP information.
Or were you trying to refer to GetHostAddresses[^]? I wonder what that does...
|
|
|
|
|
I was trying to get my PC's IPv4 address...
|
|
|
|
|
You probably need them both, since the GetHostEntry needs the host name to work from. Either that or the IP address, which (given that that is what you are trying to get) you probably haven't got...
Have a look at this: Retrieving IP and MAC addresses for a LAN[^] It does more than you need in that it returns the IP and MAC for your PC as well as that info for other LAN based devices, but it's pretty clear how it works.
[edit]Typo: "guven" for "given" - OriginalGriff[/edit]
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Hi,
I am dynamically creating Dropdownlist on server side like this:
Default.aspx page code:
Default.cs.aspx code:
On Page_Load()
{
test();
}
private void test()
{
string str = string.Empty;
str += "";
str += "ABC";
str += "EEE";
str += "EEEE";
str += "DEE";
str += "";
dropdownList.InnerHtml = str;
}
private void Save()
{
DropDownList drp = (DropDownList)this.FindControl("ddl_11");
string str = drp.SelectedValue;
}
While saving i want to get the selected value of dynamically created dropdownlist. but when i am debugging code and found that FindControl() didnt find the "ddl_11" on page its giving me NULL value.
How can i find the dynamically created dropdownlist?
Please help me i am stucked on this from last one week and didnt find any solution please help me guys.
~~~Charanjot Singh~~~
|
|
|
|
|
Hi guys, I have a FlowLayoutPanel containing unspecified number of Label ,when double click in one of them, a new Form containing a TextBox and a Button will appear, here is the code:
...
foreach (Label lb in FlowLayoutPanel1.Controls)
{
lb.MouseDoubleClick+=new MouseEventHandler(lb_MouseDoubleClick);
}
...
private void lb_MouseDoubleClick(object sender, MouseEventArgs e)
{
NewForm form = new NewForm();
form.ShowDialog();
((Label)sender).Text = ...;
}
I want get Text from TextBox of the NewForm and assign Text to the object that invoke the Form when user click the Button of the Form, I don't know how to use delegate to do this, please help! Thanks for reading this!
|
|
|
|
|
You could loop through the Controls collection of the new form, looking for the text box. Then read its text property.
foreach (Control C in form.Controls)
if (C is TextBox)
((Label)sender).Text = ((TextBox)C).Text;
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Thank Richard, but is there another way using delegate? I want to know it for learning purpose.
|
|
|
|
|
Sorry Richard, but that is a very bad idea! Just because Microsoft declare the Controls array as public doesn't mean you should use it for a simple task as it locks the design of the two forms together - you can't change NewForm without considering any effect it might have on existing code. Using a Property to access the data in NewForm is a much more OOPs solution!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
You wouldn't use a delegate for that - you would use a property in the NewForm instead.
public string Text
{
get { return myTextBox.Text; }
set { myTextBox.Text = value; }
} To even try to use a delegate for that is overcomplicating things, and opening up a route to problems.
Delegates are very powerful, but they shouldn't be used when there are better alternatives!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
Thank you OriginalGriff, that's a good idea ,just because I want to understand delegate more carefully.
|
|
|
|
|
You're welcome!
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|
What hasn't been mentioned to you is why you wouldn't use a delegate here. Basically, ShowDialog is a blocking operation so the new form blocks the originating form until it has finished processing, so retrieving the value from a known property is a much better option.
|
|
|
|