Archive for July 2nd, 2008

How to add a filelist directory to combo in winform c#

where sPath is the location of directory

DirectoryInfo di = new DirectoryInfo(sPath);
FileInfo[] rgFiles = di.GetFiles(“*.jpg”);
foreach (FileInfo fi in rgFiles)
{

string sfile = fi.Name;
sfile = sfile.Replace(“.jpg”, “”);
object obj=sfile;
ckboxTemplates.Items.Add(obj);
}

Add comment July 2, 2008

Save node tree to xml

this is a function to save node to xml

private void SaveNodesXML(TreeNodeCollection nodesCollection,
XmlWriter textWriter)
{

for (int i = 0; i < nodesCollection.Count; i++)
{
TreeNode node = nodesCollection[i];
textWriter.WriteStartElement(XmlNodeTag);
textWriter.WriteAttributeString(XmlNodeTextAtt, node.Text);
textWriter.WriteAttributeString(XmlNodeImageIndexAtt, node.ImageIndex.ToString());
if (node.Tag != null)
textWriter.WriteAttributeString(XmlNodeTagAtt, node.Tag.ToString());

if (node.Nodes.Count > 0)
{

SaveNodesXML(node.Nodes, textWriter);

}
textWriter.WriteEndElement();

}
}

Add comment July 2, 2008

how to copy a directory in c-sharp

this is a function  to copy all files in a directory.

public static void Copy(DirectoryInfo diSource, DirectoryInfo diDestination, string FileFilter, string DirectoryFilter, bool Overwrite, int FolderLimit)
{
int iterator = 0;
List<DirectoryInfo> diSourceList = new List<DirectoryInfo>();
List<FileInfo> fiSourceList = new List<FileInfo>();

try
{
///// Error Checking /////
if (diSource == null)
throw new ArgumentException(“Source Directory: NULL”);
if (diDestination == null)
throw new ArgumentException(“Destination Directory: NULL”);
if (!diSource.Exists)
throw new IOException(“Source Directory: Does Not Exist”);
if (!(FolderLimit > 0))
throw new ArgumentException(“Folder Limit: Less Than 1″);
if (DirectoryFilter == null || DirectoryFilter == string.Empty)
DirectoryFilter = “*”;
if (FileFilter == null || FileFilter == string.Empty)
FileFilter = “*”;

///// Add Source Directory to List /////
diSourceList.Add(diSource);

///// First Section: Get Folder/File Listing /////
while (iterator < diSourceList.Count && iterator < FolderLimit)
{
foreach (DirectoryInfo di in diSourceList[iterator].GetDirectories(DirectoryFilter))
diSourceList.Add(di);

foreach (FileInfo fi in diSourceList[iterator].GetFiles(FileFilter))
fiSourceList.Add(fi);

iterator++;
}

///// Second Section: Create Folders from Listing /////
foreach (DirectoryInfo di in diSourceList)
{
if (di.Exists)
{
string sFolderPath = diDestination.FullName + @”\” + di.FullName.Remove(0, diSource.FullName.Length);

///// Prevent Silly IOException /////
if (!Directory.Exists(sFolderPath))
Directory.CreateDirectory(sFolderPath);
}
}

///// Third Section: Copy Files from Listing /////
foreach (FileInfo fi in fiSourceList)
{
if (fi.Exists)
{
string sFilePath = diDestination.FullName + @”\” + fi.FullName.Remove(0, diSource.FullName.Length);

///// Better Overwrite Test W/O IOException from CopyTo() /////
if (Overwrite)
fi.CopyTo(sFilePath, true);
else
{
///// Prevent Silly IOException /////
if (!File.Exists(sFilePath))
fi.CopyTo(sFilePath, true);
}
}
}
}
catch
{ throw; }
}

Add comment July 2, 2008

how to Fill_Combol()

it’s easy… where cblProject is the combol for fill…

public void Fill_Combol()
{
SqlCommand com = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
da.TableMappings.Add(“Table”, “hforms”);
com.Connection = SoftCD.StartForm.MSSqlcon;
com.CommandType = CommandType.Text;
com.CommandText = “select PRID,PR_DESCR from LibProject order by PR_DESCR “;
da.SelectCommand = com;
da.SelectCommand.ExecuteNonQuery();
da.Fill(ds);

cblProject.DataSource = ds.DefaultViewManager;
cblProject.DisplayMember = “hforms.PR_DESCR”;
cblProject.ValueMember = “hforms.PRID”;
}

Add comment July 2, 2008


Archives

Other

Categories

 

July 2008
M T W T F S S
« Jun   Aug »
 123456
78910111213
14151617181920
21222324252627
28293031  

Tags

.net 1.1 .net 3.0 ADO.NET all-net-news alltechnews author-pinal bsod c# c-sharp controls DataSet datasource dba dba-tool entity-framework Firefox-beta Framework internet-land internet-life java-script jsf mozilla-foundation msbuild online-tools oop php-development php-programming php5 plug-ins query script-land sql-add-on sql-backup-and-restore sql-data-storage sql-datetime sql-query sql-tips-and-tricks sqlauthority-news status-updates t-sql tech-land tech-review Visual Studio 2008 Windows Server xquery