|
Hi,
Following command is not working:
System.IO.File.Delete("C:\\ABC\\*.TXT");
Error comes: => "Illegal characters in path."
|
|
|
|
|
That won't work! It should be like this:
string[] textFiles = Directory.GetFiles("C:\\ABC\\", "*.txt", SearchOption.TopDirectoryOnly);
foreach(string file in textFiles)
{
File.Delete(file);
}
|
|
|
|
|
|
This function could not use to delete all the files.
Beside this use System.io.directory.getfiles this function will return all the filename available in the specified path. use foreach loop to get into the collection and call system.io.file.delete to delete the file into your loop for each element in the array.
you can also go for the system.io.path.getextension to check the extension that should be txt files to remove.
with regards
yogesh agarwal
|
|
|
|
|
Hello All
I want to retrive the time values stored into the database then i want to display that value into a datagrid but the problem is it will display the date also along with the time but there is no dates stored into the database.
plz help me in this issue with code.
with regards
yogesh agarwal
|
|
|
|
|
If you are not directly binding the data to the Grid, you can get the value into DateTime type and use .ToShortTimeString() method and assign to the tinme value.
If you are directly binding data to the grid, then you probably have to format the column to time format.Check if DataBound like event is available or not.
If you are providing your own SQL for data retrival use
TO_CHAR(DATE_COLUMN, 'HH:MM:SS') in sql to get the data in time format.
|
|
|
|
|
Hello Everybody,
Does anybody knows how to specify "include","library", path from command line in MSBuild.
Thanks in advance,
Regards
Abhi Lahare
|
|
|
|
|
Check out followings
You can get this by firing csc -? on .NET command prompt
- OUTPUT FILES -
/out:<file> Specify output file name (default: base name of file with main class or first file)
/target:exe Build a console executable (default) (Short form: /t:exe)
/target:winexe Build a Windows executable (Short form: /t:winexe)
/target:library Build a library (Short form: /t:library)
/target:module Build a module that can be added to another assembly (Short form: /t:module)
/delaysign[+|-] Delay-sign the assembly using only the public portion of the strong name key
/doc:<file> XML Documentation file to generate
/keyfile:<file> Specify a strong name key file
/keycontainer:<string> Specify a strong name key container
/platform:<string> Limit which platforms this code can run on: x86, Itanium, x64, or anycpu. The default is anycpu.
- INPUT FILES -
/recurse:<wildcard> Include all files in the current directory and subdirectories according to the wildcard specifications
/reference:<alias>=<file> Reference metadata from the specified assembly file using the given alias (Short form: /r)
/reference:<file list=""> Reference metadata from the specified assembly files (Short form: /r)
/addmodule:<file list=""> Link the specified modules into this assembly
- RESOURCES -
/win32res:<file> Specify a Win32 resource file (.res)
/win32icon:<file> Use this icon for the output
/resource:<resinfo> Embed the specified resource (Short form: /res)
/linkresource:<resinfo> Link the specified resource to this assembly (Short form: /linkres)
Where the resinfo format is <file>[,<string name="">[,public|private]]
- CODE GENERATION -
/debug[+|-] Emit debugging information
/debug:{full|pdbonly} Specify debugging type ('full' is default, and enables attaching a debugger to a running program)
/optimize[+|-] Enable optimizations (Short form: /o)
- ERRORS AND WARNINGS -
/warnaserror[+|-] Report all warnings as errors
/warnaserror[+|-]:<warn list=""> Report specific warnings as errors
/warn:<n> Set warning level (0-4) (Short form: /w)
/nowarn:<warn list=""> Disable specific warning messages
- LANGUAGE -
/checked[+|-] Generate overflow checks
/unsafe[+|-] Allow 'unsafe' code
/define:<symbol list=""> Define conditional compilation symbol(s) (Short form: /d)
/langversion:<string> Specify language version mode: ISO-1 or Default
- MISCELLANEOUS -
@<file> Read response file for more options
/help Display this usage message (Short form: /?)
/nologo Suppress compiler copyright message
/noconfig Do not auto include CSC.RSP file
- ADVANCED -
/baseaddress: Base address for the library to be built
/bugreport:<file> Create a 'Bug Report' file.
/codepage:<n> Specify the codepage to use when opening source files
/utf8output Output compiler messages in UTF-8 encoding
/main:<type> Specify the type that contains the entry point (ignore all other possible entry points) (Short form: /m)
/fullpaths Compiler generates fully qualified paths
/filealign:<n> Specify the alignment used for output file sections
/pdb:<file> Specify debug information file name (default: output file name with .pdb extension)
/nostdlib[+|-] Do not reference standard library (mscorlib.dll)
/lib:<file list=""> Specify additional directories to search in for references
/errorreport:<string> Specify how to handle internal compiler errors: prompt, send, queue, or none. The default is queue.
/moduleassemblyname:<string> Name of the assembly which this module will be a part of.
|
|
|
|
|
|
In my code I am manipulating/creating/destroying in memory representation of big XML file (as in a few MB of CDATA in them (embeded bitmaps)).
At some stage (and I am in no way under any memory stress as my application is using only about 500MB of memory and I have 1GB free, without counting the virtual memory) I have this out of memory exception happening, in code snippet looking like that:
=====
public static void WriteXml(System.Xml.XmlWriter writer, IEnumerable<string> resources, IResourceProvider provider)<br />
{<br />
writer.WriteStartElement("Resources");<br />
<br />
writer.WriteElementString("ResourceProvider", provider.ID.ToString());<br />
List<string> resourcesWritten = new List<string>();<br />
foreach (string resource in resources)<br />
{<br />
if (resourcesWritten.Contains(resource))<br />
continue;<br />
writer.WriteStartElement("Resource");<br />
byte[] data = provider.LoadData(resource);<br />
writer.WriteElementString("ResourceName", resource);<br />
string b64Data = Convert.ToBase64String(data);<br />
writer.WriteElementString("base64Data", b64Data);<br />
writer.WriteEndElement();<br />
resourcesWritten.Add(resource);<br />
}<br />
writer.WriteEndElement();<br />
} =====
the error stack is:
====
System.Xml.dll!System.Xml.XmlWellFormedWriter.WriteString(string text) + 0x55 bytes <br />
System.Xml.dll!System.Xml.XmlWriter.WriteElementString(string localName, string ns, string value) + 0x29 bytes <br />
System.Xml.dll!System.Xml.XmlWriter.WriteElementString(string localName, string value) + 0xb bytes <br />
> NovaMind.Data3.dll!NovaMind.Data.ResourcesHelper.WriteXml(System.Xml.XmlWriter writer = {System.Xml.XmlWellFormedWriter}, System.Collections.Generic.IEnumerable<string> resources = {NovaMind.Data.NMMapBranch.get_ResourcesInUse}, NovaMind.Data.IResourceProvider provider = {NovaMind.Data.NMDocumentPackage}) Line 27 + 0x13 bytes C# ====
When I look at the internal of the various object involved with the debugger I could see that:
data.Length ~= 7 Mb (~ 7 e+6)
and "Writer" is wrapper around a StringBuilder which MaxCapacity is around 2 GB (2e+9) and which current Length is "only" about 25 Mb (25e+6).
Now, all these numbers are huge I agree, however my memory isn't stressed at all (i still used much less than my physical memory, virtual memory notwithstanding)).
Any idea why I have OutOfMemory exceptions? how to get rid of them?
|
|
|
|
|
Hello,
How are you instanziating the XMLWriter class?
)
If you are using an IO.Stream, you should "Flush()" the XmlWriter and of course "Dispose()" the Stream. (use a using Block for that):
using(MemoryStream ms = new MemoryStream())
{
XmlTextWriter xtw = new XmlTextWriter(ms, System.Text.Encoding.UTF8);
.
.
.
xtw.WriteEndElement();
xtw.Flush();
}
)
If you are using an path, you should "Close()" the XMLWriter.
XmlTextWriter xtw = new XmlTextWriter(yourPath, System.Text.Encoding.UTF8);
.
.
.
xtw.WriteEndElement();
xtw.Close();
Hope it helps!
All the best,
Martin
|
|
|
|
|
I don't think it helps because I haven't finished my write operation yet when the error happen!
I create it like that:
StringBuilder builder = new StringBuilder();<br />
System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(builder);
|
|
|
|
|
Hi,
I am developing a C# windows application(.net 2003).
The functionality of this application is to import all the records from a csv file to a table in a SQL Server 2000.
For this i am opening a sql connection and I am using Sql command. Here i set sqlcommand timeout to 500.
I am using a for loop to insert each record into sql table. After finishing all records i am closing and disposing sql connection.
This is working fine.
For some tables it is necessary to get primary key from another table and insert that primary key along with the current table's data.
For extracting that primary key i wrote funtion. This function opens a new sql connection and sql command having timeout 500.
After fetching data i am disposing that sql connection.
This funtion is called for each record in the csv file.
After inserting approximately 200 records it is giving an Exception Message
"Timeout Expired. The timeout period elapsed prior to obtaining a connection form the pool. This may have occured because all pooled connections were in use and max pool size was reached".
How to overcome this problem. It's urgent
Any one please help me.
Thanks in Advance.
Ramu
|
|
|
|
|
Ramu.M wrote: For some tables it is necessary to get primary key from another table and insert that primary key along with the current table's data.
For extracting that primary key i wrote funtion. This function opens a new sql connection and sql command having timeout 500.
Are you using stored procedures ? If yes then you can get this primary value through an output variable. This will avoid creating connection again.
Ramu.M wrote: After inserting approximately 200 records it is giving an Exception Message
Verify your code to find how many instances of SQLConnection will be open when it reaches 200 ? Try to reduce the number of connection objects open. Make sure that all SQLConnection instances are returned back to pool.
How you are disposing the objects ?
SqlConObject.Open()
SqlConObject.Close()
SqlConObject.Dispose()
Above code will keep the connection in opened state when any error happens on do operations. So it's better to wrap the connection in between using statements. This will dispose object even though any error happens.
using (SqlConObject)
{
SqlConObject.Close()
}
|
|
|
|
|
|
Hy,
Have you tried creating a buffer or such? I mean to create a list with your queries first. When you insert a new query to the list you call the function to get the UID and then fetch the data from the CSV file and then create the query. After you have finished creating the query list just open a connection to the server and loop inside the list to insert the data.
Hope it helps
Do your best to be the best
|
|
|
|
|
|
Hi,
How to remove/delete any particular file from any particular folder/directory?
Thank you in advance
(Riaz)
|
|
|
|
|
System.IO.File.Delete(strFileName)
When you get mad...THINK twice that the only advice
Tamimi - Code
|
|
|
|
|
|
Hi,
I have created one form containing some controls like buttons, textbox, labels and all, and i want to write the Event Handler for some controls in a different class file.I am using C# windows application. How to do that???
Rakesh B.P.
|
|
|
|
|
By default event handler will be added in the same class file. So if you need to write event handler method in your other class, modify event handler reference in InitializeComponent() method to your new class.
EventHandlerClass EventHandler = new EventHandlerClass ();
this.button1.Click += new System.EventHandler(EventHandler.button1_Click);
Why you want to split your event handler code to other class ?
If you are using .NET 2005, then you can make use of partial classes. Class name will be same, but you can keep the events in separate file.
Other way is using delegates.
|
|
|
|
|
Hi,
I have a big class with plenty of methods. But some of the methods inside this is not using now. So all these methods has to be removed which have no refernce. Is there any way to know which are the methods that is not having reference ?
|
|
|
|
|
You can right click on the method and choose 'find all references' ( from memory ) it finds all the places that call a function. Or you can just search the solution for the function name. Dong it for all in one go, not that I know of.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Christian Graus wrote: You can right click on the method and choose 'find all references' ( from memory ) it finds all the places that call a function.
Thanks Christian. This what I am doing now. But it takes lot of time. And I have got lot of function to go. So I thought any way to list all the unreferenced functions. Do you know about Redgate profiler ? will that help on this issue ?
|
|
|
|