|
i want to copying array values to another array.
my vaue is store the following array:
string[] path = Directory.GetFiles(filedate);
and I want to copy, stored value in path into path1.
string[] path1= ???
thanx
|
|
|
|
|
You can do this by using Array.Copy[^] method.
Example:
string [] path = Directory.GetFiles(filedate);
if(path.Length > 0)
{
string [] path1 = new string[path.Length];
Array.Copy(path, path1, path.Length);
}
|
|
|
|
|
|
hi!
I have a directory, which contain some .txt files, .doc files and .xml files. I want to move only .xml files to another directory.
I had already done one file but i couldn't move multiple xml files.
please do my favour.
thanx & regards
|
|
|
|
|
You can move your files at once by using SHFileOperation API.
This[^] is a very good article that describes how you can use this API in C#.
One of the examples in the article shows exactly how to move multiple files.
|
|
|
|
|
Here is how i would do it:
foreach (string f in Directory.GetFiles(@"C:\MyFolder"))
{
if (f.EndsWith(".xml"))
{
string currentf = f.Substring(f.LastIndexOf('\\') + 1);
File.Move(f, @"C:\MyFolder\MyXmlFolder\" + currentf);
}
}
It iterates through every file in MyFolder and if it's an xml then move it to MyXmlFolder.
|
|
|
|
|
Thank you vey much! Islorvat
but if my file already exist in destination,then...
with regards
modified on Wednesday, August 11, 2010 7:35 AM
|
|
|
|
|
Thanx, I resolved my problems
|
|
|
|
|
you may want to read up on the System.IO.Path[^] class, which offers methods to deal with file paths.
|
|
|
|
|
Hi,
I made my custom editor for my object using listdictionary type where I store the collection of objects.
I have an ancestor form where I am trying to create the property with binded designer. That will be used for specification
of datagridview columns in inherited form. But main methods must be in an ancestor.
[Browsable(true)]
[Category("BrowserForm")]
[EditorAttribute(typeof(DisplayColumnsEditor), typeof(UITypeEditor))]
public ListDictionary DisplayColumns
{
get { return displaycolumns; }
set { displaycolumns = value; }
}
There is the code for the editor:
using System;
using System.Drawing.Design;
using System.ComponentModel;
using System.Windows.Forms.Design;
using System.Collections.Specialized;
using System.Windows.Forms;
using System.Collections;
namespace mynamespace
{
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
class DisplayColumnsEditor : UITypeEditor
{
public DisplayColumnsEditor()
{
}
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc == null)
{
return null;
}
ListDictionary editval;
if (value == null)
{
editval = new ListDictionary();
} else
{
editval = (ListDictionary)value;
}
using (DisplayColumnsEditorDialog form = new DisplayColumnsEditorDialog(editval))
{
if (edSvc.ShowDialog(form) == DialogResult.OK)
{
context.OnComponentChanged();
return (object)form.Current;
}
}
return value;
}
}
}
there is the class for the listdictionary objects:
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Windows.Forms;
namespace mynamespace
{
[Serializable()]
public class DisplayColumn : ISerializable
{
private string _name;
private string _headertext;
private string _datapropertyname;
private int _width;
public DisplayColumn()
{
this._name = "";
this._datapropertyname = "";
this._headertext = "";
this._width = 100;
}
public DisplayColumn(string colname)
{
this._name = colname;
this._datapropertyname = colname;
this._headertext = colname;
this._width = 100;
}
public string Name
{
get
{
return this._name;
}
set
{
this._name = value;
}
}
public string HeaderText
{
get
{
return this._headertext;
}
set
{
this._headertext = value;
}
}
public string DataPropertyName
{
get
{
return this._datapropertyname;
}
set
{
this._datapropertyname = value;
}
}
public int Width
{
get
{
return this._width;
}
set
{
this._width = value;
}
}
public DisplayColumn(SerializationInfo info, StreamingContext ctxt)
{
Name = (String)info.GetValue("Name", typeof(string));
DataPropertyName = (String)info.GetValue("DataPropertyName", typeof(string));
HeaderText = (String)info.GetValue("HeaderText", typeof(string));
Width = (int)info.GetValue("Width", typeof(int));
}
public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{
info.AddValue("Name", Name);
info.AddValue("DataPropertyName", DataPropertyName);
info.AddValue("HeaderText", HeaderText);
info.AddValue("Width", Width);
}
}
}
The editor uses classical windows forms(IWindowsFormsEditorService) and returns a listdictionary collection. If it will be needed I can include the code for it. But I can ensure it returns really listdictinary collection.
Tha main trouble consist of storing value into resource file of inherited form. When I use the designer
and open the resource file there is a key named: $this.DisplayColumns and not just DisplayColumns.
This name of key is problematic, because value is available only for the designer, but not present in run-time.
in inerited form's resource file it creates following node:
<data name="DisplayColumns" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD cmFsLCBQdWJsaWNLZXlUb2tlbj1iNzdhNWM1NjE5MzRlMDg5BQEAAAAtU3lzdGVtLkNvbGxlY3Rpb25z
LlNwZWNpYWxpemVkLkxpc3REaWN0aW9uYXJ5BAAAAARoZWFkB3ZlcnNpb24FY291bnQIY29tcGFyZXIE
AAADPFN5c3RlbS5Db2xsZWN0aW9ucy5TcGVjaWFsaXplZC5MaXN0RGljdGlvbmFyeStEaWN0aW9uYXJ5
Tm9kZQIAAAAICBxTeXN0ZW0uQ29sbGVjdGlvbnMuSUNvbXBhcmVyAgAAAAkDAAAABgAAAAMAAAAKDAQA
AABHU09QUlZDb3JlLCBWZXJzaW9uPTEuMC4zODcyLjI1NTAwLCBDdWx0dXJlPW5ldXRyYWwsIFB1Ymxp
Y0tleVRva2VuPW51bGwFAwAAADxTeXN0ZW0uQ29sbGVjdGlvbnMuU3BlY2lhbGl6ZWQuTGlzdERpY3Rp
b25hcnkrRGljdGlvbmFyeU5vZGUDAAAAA2tleQV2YWx1ZQRuZXh0AgQEIlNsaW0uU09QUlYuU09QUlZD
b3JlLkRpc3BsYXlDb2x1bW4EAAAAPFN5c3RlbS5Db2xsZWN0aW9ucy5TcGVjaWFsaXplZC5MaXN0RGlj
dGlvbmFyeStEaWN0aW9uYXJ5Tm9kZQIAAAACAAAABgUAAAAFR2NfSUQJBgAAAAkHAAAABQYAAAAiU2xp
bS5TT1BSVi5TT1BSVkNvcmUuRGlzcGxheUNvbHVtbgQAAAAETmFtZRBEYXRhUHJvcGVydHlOYW1lCkhl
YWRlclRleHQFV2lkdGgBAQEACAQAAAAJBQAAAAYJAAAAC2RhdGExMDBrX2lkBgoAAAACSURkAAAAAQcA
AAADAAAABgsAAAAHR2NfVEVYVAkMAAAACQ0AAAABDAAAAAYAAAAJCwAAAAYPAAAABXRleHQxBhAAAAAE
VEVYVGQAAAABDQAAAAMAAAAGEQAAAAhHY19DSVNMTwkSAAAACgESAAAABgAAAAkRAAAABhQAAAAFY2lz
bG8GFQAAAAfEjMOtc2xvZAAAAAs=
</value>
</data>
in inherited form's designer.cs it creates a row, where it loads its value:
this.DisplayColumns = ((System.Collections.Specialized.ListDictionary)(resources.GetObject("$this.DisplayColumns")));
but I would need just:
this.DisplayColumns = ((System.Collections.Specialized.ListDictionary)(resources.GetObject("DisplayColumns")));
Is there anyone, who has an idea what does this cause? Is this caused by using serialization? Or am I doing anything else wrong, beacuse I did not implement any TypeConverters? Is this normal "store key" with $ prefix of collections for resource files?
JvR
|
|
|
|
|
Sir i need to extract ECG wave from an ECG strip i m able to do it using MATLAB.. is there any way i can do it in c#.. if yes kindly brief me on the possible ways.
Thank you
|
|
|
|
|
The only way I can think of is to write some code.
Alternatively, search the web - somebody might already have done it.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
hi i have a windows service app and i want to host its object remotly.hw i can do that?
|
|
|
|
|
How to install sql server 2005 on pc accurately
|
|
|
|
|
that isn't a C# question. You should try the Database forum instead.
|
|
|
|
|
Have a look at the msdn website.
This is not a C# question anyway.
|
|
|
|
|
I cant seem to format my strAverageDensity which originally is in this example strAverageDensity = 30.000000123
using: string.Format("{0:0.00}", strAverageDensity);
need it to equal 30.00 in this case but 2 decimal places
instead its still strAverageDensity = 30.000000123
so this is the code:
EditSubCategory E = new EditSubCategory();
SubCategory C = GlobalContextManager.Instance.Cache.GetSubCategory((int)R.Cells[0].Value);
Category CC = GlobalContextManager.Instance.Cache.GetCategory(C.CategoryId);
string strAverageDensity = Convert.ToString(GlobalContextManager.Instance.Conversions.ConvertMetricWeightToDefault(C.AverageDensity));
E.ParentCategory = CC;
E.Category = C.Name;
E.IsActivated = C.IsEnabled;
E.OriginalCategory = C.Name;
strAverageDensity = string.Format("{0:0.00}", strAverageDensity);
E.AverageDensity = strAverageDensity;
|
|
|
|
|
strAverageDensity should be of type float or double and not string to take advantage of numeric format strings.
|
|
|
|
|
Try:
strAverageDensity = string.Format("{0:0.00}", C.AverageDensity); which I assume is a float / double. Strings do not use numeric formats!
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
|
|
|
|
|
you failed to show an essential line of source code. Now compare yours to this:
float f=30.01234f;
log(string.Format("{0:0.00}", f));
string s="30.01234";
log(string.Format("{0:0.00}", s));
|
|
|
|
|
As has already been pointed out, this format string works with numeric types. Why don't you try?
double dAverageDensity = Double.Parse(strAverageDensity);
strAverageDensity = String.Format("{0:0.00}", dAverageDensity);
|
|
|
|
|
hi dear friend.
i am a regular programmer,but i think this line of your program can be change
string strAverageDensity = Convert.ToString(GlobalContextManager.Instance.Conversions.ConvertMetricWeightToDefault(C.AverageDensity));
instead of Convert.ToString(...) use of System.Convert.ToString(...).
i hope success for you.
M.Shooster
|
|
|
|
|
You could try Substring....
|
|
|
|
|
substring is chopping strings, not rounding numbers.
|
|
|
|
|
He seems to want to round a string.
|
|
|
|