.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

Add New Folder Dynamically

Posted By: kamlesh     Posted Date: February 01, 2011    Points:2   Category :Windows Application
hi

i have created one application and i have take one treeview node and i want to add new folder on button so can any one help me

thanks
kamlesh nikam

Responses
Author: Vijay             
Posted Date: February 02, 2011     Points: 5   

Hi,
write this on button click event.
System.IO.Directory.CreateDirectory("C://FolderName");
Regards,
Vijay

Author: kamlesh             
Posted Date: March 22, 2011     Points: 20   

//FILE LEVEL DOCUMENTATION
/*! \file frmExport.cs
* \brief this form will Used To Restore The Multiple Folder
* \author Unitrends, Inc.
* \Date Wed. 23 Feb. 2011

* \em COPYRIGHT © 2011 Unitrends, Inc.
*
* This software is furnished under a license for use only on a
* single computer system and may be copied only with the
* inclusion of the above copyright notice. This software, or any
* other copies thereof, may not be provided or otherwise made
* available to any other person except for use on such a system
* and to one who agrees to these license terms. Title to and
* ownership of the software shall at all times remain in
* Unitrends, Inc.
*
* The information in this software is subject to change without
* notice and should not be construed as a commitment by
* Unitrends, Inc.
*
* This software is provided on an "as is" basis without any warranty
* of any kind whatsoever, either expressed or implied.
* Unitrends, Inc. does not warrant the software to be error
* free, nor does it warrant that it will meet your specific requirements.
*/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
using System.Threading;

/*!
* \namespace OutlookDemo
* \brief namespace for Handling all the Forms Which are include in the frmManager
* \Date Wed. 23 Feb. 2011
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

namespace OutlookDemo
{
/*! A CLASS */
/*! \class class frmExport
* \brief Used To Used To Restore The Multiple Folder
* \author Unitrends, Inc.
* \Date 23 Feb 2011
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

public partial class frmExport : Form
{
//Thread th;

public frmExport()
{
InitializeComponent();
}

/*! \fn private void frmExport_Load(object sender, EventArgs e)
* \brief constructor to Load Event of frmExport
* \author Unitrends, Inc.
* \date 23 Feb 2011 *
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

private void frmExport_Load(object sender, EventArgs e)
{
//pictureBox1.Visible = false;
drawTree();
RdoButnLiveExchangeServer.Checked = true;

}

/*! \fn private void drawTree()
* \brief constructor to SHow hierarchical Structure of TreeMailNode
* \author Unitrends, Inc.
* \date 23 Feb 2011 *
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

private void drawTree()
{
try
{
TreeMailNodes.Nodes.Clear();
TreeMailNodes.CheckBoxes = true;


List<MailNodesDTO> NodeList = MailService.GetNodeList();
bool isExpended = false;
foreach (MailNodesDTO NodeDTO in NodeList)
{
TreeNode RouteNode = new TreeNode();

FileInfo file = new FileInfo(NodeDTO.RouteFolder.Name);
String routFolder = file.Name;
if (routFolder.Length > 4)
{
routFolder = routFolder.Substring(0, routFolder.Length - 4);
}
RouteNode.Text = routFolder;//NodeDTO.RouteFolder.Name;
RouteNode.Tag = NodeDTO.RouteFolder.ID;
foreach (MailSubFolderDTO SubFolderDTO in NodeDTO.SubFolderDTOList)
{
if (SubFolderDTO.Lavel == 1)
{
TreeNode SubNode = new TreeNode();
SubNode.Text = SubFolderDTO.Name;
SubNode.Tag = SubFolderDTO.ID;


string ItemType = SubFolderDTO.Name.Trim().ToLower();
SetTreeNodeIcon(SubNode, ItemType);
if (SubFolderDTO.ChieldNodeList.Count > 0)
{
List<TreeNode> TempNodeList = GetSubTreeNode(SubFolderDTO.ChieldNodeList);
for (int n = 0; n < TempNodeList.Count; n++)
{
SubNode.Nodes.Add(TempNodeList[n]);
}
}
RouteNode.Nodes.Add(SubNode);



}
}
TreeMailNodes.Nodes.Add(RouteNode);
if (!isExpended)
{
RouteNode.Expand();
isExpended = true;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
clsError.LogError(ex);
}
}

/*! \fn private void TreeMailNodes_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
* \brief constructor to Click on Tree Mail NOde of Node Mouse Click
* \author Unitrends, Inc.
* \date 23 Feb 2011 *
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

private void TreeMailNodes_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
TreeMailNodes.SelectedNode = e.Node;
TreeMailNodes.SelectedNode = e.Node;


foreach (TreeNode otree in e.Node.Nodes)
{
otree.Checked = e.Node.Checked;
CheckName(otree, e.Node.Checked);

}
//Changes
if (e.Node.Level > 0)
{
if (e.Node.Parent.Checked == true)
{

e.Node.Checked = true;
//CheckTrue(osub, true);
CheckTrue(e.Node.Parent, true);


}
}
}

/*! \fn private void CheckTrue(TreeNode oTree, Boolean Check)
* \brief constructor to Check True
* \author Unitrends, Inc.
* \date 23 Feb 2011 *
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

private void CheckTrue(TreeNode oTree, Boolean Check)
{
foreach (TreeNode oSub in oTree.Nodes)
{

oSub.Checked = true;
CheckTrue(oSub, true);
//CheckTrue(oSub.Parent, true);
}
}

/*! \fn private void CheckName(TreeNode oTree, Boolean Check)
* \brief constructor to Check Name
* \author Unitrends, Inc.
* \date 23 Feb 2011 *
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

private void CheckName(TreeNode oTree, Boolean Check)
{
foreach (TreeNode oSub in oTree.Nodes)
{
oSub.Checked = oTree.Checked;

CheckName(oSub, oTree.Checked);

}
}

/*! \fn private List<TreeNode> GetSubTreeNode(List<MailSubFolderDTO> SubNodeList)
* \brief constructor to Get Sub Tree Node
* \author Unitrends, Inc.
* \date 23 Feb 2011 *
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

private List<TreeNode> GetSubTreeNode(List<MailSubFolderDTO> SubNodeList)
{
List<TreeNode> TempChieldNodeList = new List<TreeNode>();
foreach (MailSubFolderDTO SubFolderDTO in SubNodeList)
{
TreeNode SubNode = new TreeNode();
SubNode.Text = SubFolderDTO.Name;
SubNode.Tag = SubFolderDTO.ID;
string ItemType = SubFolderDTO.Name.Trim().ToLower();
SetTreeNodeIcon(SubNode, ItemType);
if (SubFolderDTO.ChieldNodeList.Count > 0)
{
List<TreeNode> TempNodeList = GetSubTreeNode(SubFolderDTO.ChieldNodeList);
for (int n = 0; n < TempNodeList.Count; n++)
{
SubNode.Nodes.Add(TempNodeList[n]);
}
}
TempChieldNodeList.Add(SubNode);
}

return TempChieldNodeList;
}

/*! \fn private TreeNode SetTreeNodeIcon(TreeNode SubNode, string ItemType)
* \brief constructor to Set Icons To Tree Node
* \author Unitrends, Inc.
* \date 23 Feb 2011 *
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

private TreeNode SetTreeNodeIcon(TreeNode SubNode, string ItemType)
{
ItemType = ItemType.ToLower();
switch (ItemType)
{
case "tasks":
SubNode.ImageIndex = 10;
SubNode.SelectedImageIndex = 10;
break;
case "deleted items":
SubNode.ImageIndex = 8;
SubNode.SelectedImageIndex = 8;
break;
case "notes":
SubNode.ImageIndex = 5;
SubNode.SelectedImageIndex = 5;
break;
case "calendar":
SubNode.ImageIndex = 11;
SubNode.SelectedImageIndex = 11;
break;
case "contacts":
SubNode.ImageIndex = 2;
SubNode.SelectedImageIndex = 2;
break;
case "journal":
SubNode.ImageIndex = 12;
SubNode.SelectedImageIndex = 12;
break;
case "inbox":
SubNode.ImageIndex = 1;
SubNode.SelectedImageIndex = 1;
break;
case "sent items":
SubNode.ImageIndex = 4;
SubNode.SelectedImageIndex = 4;
break;
case "outbox":
SubNode.ImageIndex = 7;
SubNode.SelectedImageIndex = 7;
break;
case "drafts":
SubNode.ImageIndex = 3;
SubNode.SelectedImageIndex = 3;
break;
case "junk e-mail":
SubNode.ImageIndex = 6;
SubNode.SelectedImageIndex = 6;
break;
case "rss feeds":
SubNode.ImageIndex = 9;
SubNode.SelectedImageIndex = 9;
break;
default:
SubNode.ImageIndex = 0;
SubNode.SelectedImageIndex = 0;
break;
}
return SubNode;
}

/*! \fn private void BtnSubmit_Click(object sender, EventArgs e)
* \brief constructor to Submit Button Click
* \author Unitrends, Inc.
* \date 23 Feb 2011 *
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

private void BtnSubmit_Click(object sender, EventArgs e)
{

if (TreeMailNodes.SelectedNode == null)
{
MessageBox.Show("Please Import PST or EDB File");
this.Close();
}
else
{

/// <summary>
/// Restore to Live Exchange Server
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

if (TreeMailNodes.SelectedNode.Checked)
{

if (RdoButnLiveExchangeServer.Checked == true)
{
// Exoprt Live Exchange Server
try
{


if (TreeMailNodes.SelectedNode != null)
{
string NodeName = "";
string strNodes = TreeMailNodes.SelectedNode.FullPath;
String[] Nodes = strNodes.Split('\\');
//Nodes.Remove(0);

for (int i = 1; i < Nodes.Length; i++)
{

NodeName = NodeName + Nodes[i];
if (i != Nodes.Length - 1)
NodeName = NodeName + "\\";

}
if (TreeMailNodes.SelectedNode.Level > 0)
{

List<ClsExportUserMetaData> userList = new List<ClsExportUserMetaData>();

List<clsExportFolder> folderList = new List<clsExportFolder>();
int userCount = 0;
clsExport Export = new clsExport();
foreach (TreeNode oTree in TreeMailNodes.Nodes)
{
ClsExportUserMetaData user = new ClsExportUserMetaData();
//user.UserName = "";
IterateFolders(oTree, ref folderList);

if (folderList.Count > 0)
{

string RouteFolderName = MailService.GetRouteFolderName(Convert.ToInt64(oTree.Tag/*TreeMailNodes.SelectedNode.Tag*/));
//userCount++;
user.ExportType = ExportTypeEnum.Selected;
user.UserName = RouteFolderName;
user.FolderList.AddRange(folderList);
user.FolderCount = folderList.Count;
userList.Add(user);
userCount++;
}
folderList.Clear();


}
if (userCount != 0)
{
Export.UserCount = userCount;

Export.UserList = userList;
ClsExportCreateXML XMLCreater = new ClsExportCreateXML();
XMLCreater.CreateXML(Export);
}
//End
///////////////////////////////////////////////////////////


}

else
{

// Route Folder
List<ClsExportUserMetaData> userList = new List<ClsExportUserMetaData>();
//ClsExportUserMetaData user = new ClsExportUserMetaData();
clsExport Export = new clsExport();
int userCount = 0;
foreach (TreeNode oTree in TreeMailNodes.Nodes)
{
ClsExportUserMetaData user = new ClsExportUserMetaData();
//user.UserName = "";
if (oTree.Checked == true)
{
string RouteFolderName = MailService.GetRootFolderName(Convert.ToInt64(oTree.Tag));



user.ExportType = ExportTypeEnum.Full;
user.UserName = RouteFolderName;
userList.Add(user);
userCount++;
}
}

if (userCount != 0)
{
Export.UserCount = Export.UserList.Count;
Export.UserList = userList;
ClsExportCreateXML XMLCreater = new ClsExportCreateXML();
XMLCreater.CreateXML(Export);
}
}

//MessageBox.Show("Live Exchange Server");

CLICaller.bIsPublicFolderRestore = false;
FrmRestore frmres = new FrmRestore();
frmres.ShowDialog();
this.Close();
}



}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
clsError.LogError(ex);
}
// MessageBox.Show("Live Exchange Server");
}

/// <summary>
/// Restore to MSG
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

else if (RdoButnMSG.Checked == true)
{

if (TreeMailNodes.SelectedNode != null)
{
string NodeName = "";
string strNodes = TreeMailNodes.SelectedNode.FullPath;
String[] Nodes = strNodes.Split('\\');
//Nodes.Remove(0);

for (int i = 1; i < Nodes.Length; i++)
{

NodeName = NodeName + Nodes[i];
if (i != Nodes.Length - 1)
NodeName = NodeName + "\\";

}
if (TreeMailNodes.SelectedNode.Level > 0)
{

List<ClsExportUserMetaData> userList = new List<ClsExportUserMetaData>();

List<clsExportFolder> folderList = new List<clsExportFolder>();
int userCount = 0;
clsExport Export = new clsExport();
foreach (TreeNode oTree in TreeMailNodes.Nodes)
{
ClsExportUserMetaData user = new ClsExportUserMetaData();
//user.UserName = "";
IterateFolders(oTree, ref folderList);

if (folderList.Count > 0)
{

string RouteFolderName = MailService.GetRouteFolderName(Convert.ToInt64(oTree.Tag/*TreeMailNodes.SelectedNode.Tag*/));
//userCount++;
user.ExportType = ExportTypeEnum.Selected;
user.UserName = RouteFolderName;
user.FolderList.AddRange(folderList);
user.FolderCount = folderList.Count;
userList.Add(user);
userCount++;
}
folderList.Clear();


}
if (userCount != 0)
{
Export.UserCount = userCount;

Export.UserList = userList;
ClsExportCreateXML XMLCreater = new ClsExportCreateXML();
XMLCreater.CreateXML(Export);
}
//End
///////////////////////////////////////////////////////////


}

else
{

// Route Folder
List<ClsExportUserMetaData> userList = new List<ClsExportUserMetaData>();
//ClsExportUserMetaData user = new ClsExportUserMetaData();
clsExport Export = new clsExport();
int userCount = 0;
foreach (TreeNode oTree in TreeMailNodes.Nodes)
{
ClsExportUserMetaData user = new ClsExportUserMetaData();
//user.UserName = "";
if (oTree.Checked == true)
{
string RouteFolderName = MailService.GetRootFolderName(Convert.ToInt64(oTree.Tag));



user.ExportType = ExportTypeEnum.Full;
user.UserName = RouteFolderName;
userList.Add(user);
userCount++;
}
}

if (userCount != 0)
{
Export.UserCount = Export.UserList.Count;
Export.UserList = userList;
ClsExportCreateXML XMLCreater = new ClsExportCreateXML();
XMLCreater.CreateXML(Export);
}
}

FolderBrowserDialog browsefolder = new FolderBrowserDialog();


if (browsefolder.ShowDialog() == DialogResult.OK)
{

browsefolder.Dispose();

Thread.Sleep(500);

frmLoading frmload = new frmLoading();
frmload.Show();

try
{

String pstFilePath = null;
List<ExportToMsg.UserInfo> lsUserInfoList = new List<ExportToMsg.UserInfo>();


ExportToMsg.ReadXMLFile(System.Environment.CurrentDirectory + "\\ExportMail.xml", ref lsUserInfoList);
for (int iUserCount = 0; iUserCount < lsUserInfoList.Count; iUserCount++)
{
ExportToMsg.strFullFolderPath = "";
ExportToMsg.strRootFolder = null;

pstFilePath = lsUserInfoList[iUserCount].strUserName;

string pstName = null;
String strSaveFolderPath = browsefolder.SelectedPath;
Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace outlookNs = app.GetNamespace("MAPI");

String strGUID = Guid.NewGuid().ToString();
//CLICaller.ProfileHandling(strGUID, 1,pstFilePath );

//outlookNs.Logon(strGUID, null, null, true);
outlookNs.AddStore(pstFilePath);

Microsoft.Office.Interop.Outlook.MAPIFolder rootFolder = null;
Microsoft.Office.Interop.Outlook.Stores Store1 = outlookNs.Stores;
foreach (Microsoft.Office.Interop.Outlook.Store item_Store in Store1)
{
string StoreName = item_Store.DisplayName;

if (StoreName == "Personal Folders")
pstName = "Personal Folders";
if (StoreName == "Source Folder")
pstName = "Source Folder";
if (StoreName == "Destination Folder")
pstName = "Destination Folder";
}
rootFolder = outlookNs.Stores[pstName].GetRootFolder();
Microsoft.Office.Interop.Outlook.Folders subFolders = rootFolder.Folders;

if (lsUserInfoList[iUserCount].strType1 == "Full")
{
foreach (Microsoft.Office.Interop.Outlook.Folder folder in subFolders)
{
ExportToMsg.GetSubFolders(folder, strSaveFolderPath, "", lsUserInfoList[iUserCount], 0);
}
}
else
if (lsUserInfoList[iUserCount].strType1 == "Selected")
{
for (int iFolderCount = 0; iFolderCount < lsUserInfoList[iUserCount].lsItemInfo.Count; iFolderCount++)
{
ExportToMsg.strRootFolder = lsUserInfoList[iUserCount].lsItemInfo[iFolderCount].strFolderName.Split('\\');
if (lsUserInfoList[iUserCount].strType2 == "Full")
{
foreach (Microsoft.Office.Interop.Outlook.Folder folder in subFolders)
{
if (ExportToMsg.strRootFolder[0] == folder.Name)
{
ExportToMsg.strFullFolderPath = folder.Name;
ExportToMsg.GetSubFolders(folder, strSaveFolderPath, lsUserInfoList[iUserCount].lsItemInfo[iFolderCount].strFolderName, lsUserInfoList[iUserCount], iFolderCount);
}
}
}
else if (lsUserInfoList[iUserCount].strType2 == "Selected")
{
foreach (Microsoft.Office.Interop.Outlook.Folder folder in subFolders)
{
if (ExportToMsg.strRootFolder[0] == folder.Name)
{
ExportToMsg.strFullFolderPath = folder.Name;
ExportToMsg.GetSubFolders(folder, strSaveFolderPath, lsUserInfoList[iUserCount].lsItemInfo[iFolderCount].strFolderName, lsUserInfoList[iUserCount], iFolderCount);
}
}
}

}
}
outlookNs.RemoveStore(rootFolder);
//outlookNs.Logoff();
//CLICaller.ProfileHandling(strGUID, 2,"");
}

frmload.Close();

MessageBox.Show("Export to MSG is Completed", "Export", MessageBoxButtons.OK, MessageBoxIcon.None);

Process[] GetAllProcesses = Process.GetProcessesByName("OUTLOOK");
for (int i = 0; i < GetAllProcesses.Length; i++)
{
GetAllProcesses[i].Kill();
}

Thread.Sleep(200);
File.Delete(Path.GetDirectoryName(pstFilePath) + @"\~" + Path.GetFileName(pstFilePath) + ".tmp");
this.Close();

}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
Process[] GetAllProcesses = Process.GetProcessesByName("OUTLOOK");
for (int i = 0; i < GetAllProcesses.Length; i++)
{
GetAllProcesses[i].Kill();
}
}


}
else
{
browsefolder.Dispose();
}
browsefolder.Dispose();
browsefolder = null;
}
}

/// <summary>
/// Restore to PST Files
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

else if (RdoButnPST.Checked == true)
{

if (TreeMailNodes.SelectedNode != null)
{
string NodeName = "";
string strNodes = TreeMailNodes.SelectedNode.FullPath;
String[] Nodes = strNodes.Split('\\');
//Nodes.Remove(0);

for (int i = 1; i < Nodes.Length; i++)
{

NodeName = NodeName + Nodes[i];
if (i != Nodes.Length - 1)
NodeName = NodeName + "\\";

}
if (TreeMailNodes.SelectedNode.Level > 0)
{

List<ClsExportUserMetaData> userList = new List<ClsExportUserMetaData>();

List<clsExportFolder> folderList = new List<clsExportFolder>();
int userCount = 0;
clsExport Export = new clsExport();
foreach (TreeNode oTree in TreeMailNodes.Nodes)
{
ClsExportUserMetaData user = new ClsExportUserMetaData();
//user.UserName = "";
IterateFolders(oTree, ref folderList);

if (folderList.Count > 0)
{

string RouteFolderName = MailService.GetRouteFolderName(Convert.ToInt64(oTree.Tag/*TreeMailNodes.SelectedNode.Tag*/));
//userCount++;
user.ExportType = ExportTypeEnum.Selected;
user.UserName = RouteFolderName;
user.FolderList.AddRange(folderList);
user.FolderCount = folderList.Count;
userList.Add(user);
userCount++;
}
folderList.Clear();


}
if (userCount != 0)
{
Export.UserCount = userCount;

Export.UserList = userList;
ClsExportCreateXML XMLCreater = new ClsExportCreateXML();
XMLCreater.CreateXML(Export);
}
//End
///////////////////////////////////////////////////////////


}

else
{

// Route Folder
List<ClsExportUserMetaData> userList = new List<ClsExportUserMetaData>();
//ClsExportUserMetaData user = new ClsExportUserMetaData();
clsExport Export = new clsExport();
int userCount = 0;
foreach (TreeNode oTree in TreeMailNodes.Nodes)
{
ClsExportUserMetaData user = new ClsExportUserMetaData();
//user.UserName = "";
if (oTree.Checked == true)
{
string RouteFolderName = MailService.GetRootFolderName(Convert.ToInt64(oTree.Tag));



user.ExportType = ExportTypeEnum.Full;
user.UserName = RouteFolderName;
userList.Add(user);
userCount++;
}
}

if (userCount != 0)
{
Export.UserCount = Export.UserList.Count;
Export.UserList = userList;
ClsExportCreateXML XMLCreater = new ClsExportCreateXML();
XMLCreater.CreateXML(Export);
}
} //MessageBox.Show("Live Exchange Server");

CLICaller.bIsPublicFolderRestore = false;
// Create new SaveFileDialog object
SaveFileDialog DialogSave = new SaveFileDialog();




DialogSave.DefaultExt = "pst";
DialogSave.Filter = "Personal Folder (*.pst)|*.pst";
// Adds a extension if the user does not
DialogSave.AddExtension = true;
// Restores the selected directory, next time
DialogSave.RestoreDirectory = true;
// Dialog title
DialogSave.Title = "Where do you want to save the file?";
// Startup directory
DialogSave.InitialDirectory = @"C:/";
// Show the dialog and process the result
if (DialogSave.ShowDialog() == DialogResult.OK)
{
CLICaller.RestoreDataToUser("", DialogSave.FileName, System.Environment.CurrentDirectory + "\\ExportMail.xml", "");
MessageBox.Show("Restore Completed Successfully", "Restore", MessageBoxButtons.OK, MessageBoxIcon.None);
this.Close();
}
else
{
DialogSave.Dispose();
}

DialogSave.Dispose();
DialogSave = null;
}
}
/// <summary>
/// Restore to Public Folder
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>

else if (RdoButnPublicFolder.Checked == true)
{
//MessageBox.Show("Public Folder");
if (TreeMailNodes.SelectedNode != null)
{
string NodeName = "";
string strNodes = TreeMailNodes.SelectedNode.FullPath;
String[] Nodes = strNodes.Split('\\');
//Nodes.Remove(0);

for (int i = 1; i < Nodes.Length; i++)
{

NodeName = NodeName + Nodes[i];
if (i != Nodes.Length - 1)
NodeName = NodeName + "\\";

}
if (TreeMailNodes.SelectedNode.Level > 0)
{

List<ClsExportUserMetaData> userList = new List<ClsExportUserMetaData>();

List<clsExportFolder> folderList = new List<clsExportFolder>();
int userCount = 0;
clsExport Export = new clsExport();
foreach (TreeNode oTree in TreeMailNodes.Nodes)
{
ClsExportUserMetaData user = new ClsExportUserMetaData();
//user.UserName = "";
IterateFolders(oTree, ref folderList);

if (folderList.Count > 0)
{

string RouteFolderName = MailService.GetRouteFolderName(Convert.ToInt64(oTree.Tag/*TreeMailNodes.SelectedNode.Tag*/));
//userCount++;
user.ExportType = ExportTypeEnum.Selected;
user.UserName = RouteFolderName;
user.FolderList.AddRange(folderList);
user.FolderCount = folderList.Count;
userList.Add(user);
userCount++;
}
folderList.Clear();


}
if (userCount != 0)
{
Export.UserCount = userCount;

Export.UserList = userList;
ClsExportCreateXML XMLCreater = new ClsExportCreateXML();
XMLCreater.CreateXML(Export);
}
//End
///////////////////////////////////////////////////////////


}

else
{

// Route Folder
List<ClsExportUserMetaData> userList = new List<ClsExportUserMetaData>();
//ClsExportUserMetaData user = new ClsExportUserMetaData();
clsExport Export = new clsExport();
int userCount = 0;
foreach (TreeNode oTree in TreeMailNodes.Nodes)
{
ClsExportUserMetaData user = new ClsExportUserMetaData();
//user.UserName = "";
if (oTree.Checked == true)
{
string RouteFolderName = MailService.GetRootFolderName(Convert.ToInt64(oTree.Tag));



user.ExportType = ExportTypeEnum.Full;
user.UserName = RouteFolderName;
userList.Add(user);
userCount++;
}
}

if (userCount != 0)
{
Export.UserCount = Export.UserList.Count;
Export.UserList = userList;
ClsExportCreateXML XMLCreater = new ClsExportCreateXML();
XMLCreater.CreateXML(Export);
}
}

CLICaller.bIsPublicFolderRestore = true;

FrmRestore frmrest = new FrmRestore();
frmrest.ShowDialog(this);

this.Close();
}

}

/// <summary>
/// Restore to XML
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
///
else if (RdoButnXML.Checked == true)
{


//////////////////////////////////////////////////
string NodeName = "";
string strNodes = TreeMailNodes.SelectedNode.FullPath;
String[] Nodes = strNodes.Split('\\');
//Nodes.Remove(0);

for (int i = 1; i < Nodes.Length; i++)
{

NodeName = NodeName + Nodes[i];
if (i != Nodes.Length - 1)
NodeName = NodeName + "\\";

}

FolderBrowserDialog browsefolder = new FolderBrowserDialog();


if (browsefolder.ShowDialog() == DialogResult.OK)
{

browsefolder.Dispose();

Thread.Sleep(500);

frmLoading frmload = new frmLoading();
frmload.Show();

string RouteFolderName = MailService.GetRouteFolderName(Convert.ToInt64(TreeMailNodes.SelectedNode.Tag));
ClsExportXML ExportXML = new ClsExportXML();
//ExportXML.UserCountXML = 1;
List<ClsExportUserMetaDataForXML> UserListXML = new List<ClsExportUserMetaDataForXML>();
ClsExportUserMetaDataForXML UserXML = new ClsExportUserMetaDataForXML();
UserXML.ExportTypeXML = ExportTypeEnumXML.Selected;
UserXML.UserNameXML = RouteFolderName;
List<ClsExportFolderXML> folderListXML = new List<ClsExportFolderXML>();
ClsExportFolderXML folderXML1 = new ClsExportFolderXML();
folderXML1.ExportTypeXML = ExportTypeEnumXML.Selected;
folderXML1.FolderNameXML = NodeName;
List<ClsExportMailXML> MailXMLList = new List<ClsExportMailXML>();
List<ClsExportTaskXML> TaskXMLList = new List<ClsExportTaskXML>();
List<ClsExportContactXML> ContactXMLList = new List<ClsExportContactXML>();
List<ClsExportJournalXML> JournalXMLList = new List<ClsExportJournalXML>();
List<ClsExportCalendarXML> CalendarXMLList = new List<ClsExportCalendarXML>();
List<ClsExportNotesXML> NoteXMLList = new List<ClsExportNotesXML>();



/////////////////////////////////////////////////////
if (TreeMailNodes.SelectedNode.Level >= 0)
{
List<clsExportFolder> folderList = new List<clsExportFolder>();
foreach (TreeNode oTree in TreeMailNodes.Nodes)
{
if (oTree.Checked == false)
IterateFoldersXML(oTree, ref folderList, browsefolder.SelectedPath);
else if (oTree.Checked == true)
IterateFoldersXMLAll(oTree, ref folderList, browsefolder.SelectedPath);
}
}

frmload.Close();
MessageBox.Show("Export To XML is completed", "Exported", MessageBoxButtons.OK, MessageBoxIcon.None);
this.Close();
}
else
{
browsefolder.Dispose();
}

browsefolder.Dispose();
}
else
this.Close();
}
else
{
MessageBox.Show("No Folders Selected");
}

}
}


//public void CallbackForXML()
//{
// ////////////////////////////////////////////////////
// string NodeName = "";
// string strNodes = TreeMailNodes.SelectedNode.FullPath;
// String[] Nodes = strNodes.Split('\\');
// //Nodes.Remove(0);

// for (int i = 1; i < Nodes.Length; i++)
// {
// NodeName = NodeName + Nodes[i];
// if (i != Nodes.Length - 1)
// NodeName = NodeName + "\\";
// }


// string RouteFolderName = MailService.GetRouteFolderName(Convert.ToInt64(TreeMailNodes.SelectedNode.Tag));
// ClsExportXML ExportXML = new ClsExportXML();
// //ExportXML.UserCountXML = 1;
// List<ClsExportUserMetaDataForXML> UserListXML = new List<ClsExportUserMetaDataForXML>();
// ClsExportUserMetaDataForXML UserXML = new ClsExportUserMetaDataForXML();
// UserXML.ExportTypeXML = ExportTypeEnumXML.Selected;
// UserXML.UserNameXML = RouteFolderName;
// List<ClsExportFolderXML> folderListXML = new List<ClsExportFolderXML>();
// ClsExportFolderXML folderXML1 = new ClsExportFolderXML();
// folderXML1.ExportTypeXML = ExportTypeEnumXML.Selected;
// folderXML1.FolderNameXML = NodeName;
// List<ClsExportMailXML> MailXMLList = new List<ClsExportMailXML>();
// List<ClsExportTaskXML> TaskXMLList = new List<ClsExportTaskXML>();
// List<ClsExportContactXML> ContactXMLList = new List<ClsExportContactXML>();
// List<ClsExportJournalXML> JournalXMLList = new List<ClsExportJournalXML>();
// List<ClsExportCalendarXML> CalendarXMLList = new List<ClsExportCalendarXML>();
// List<ClsExportNotesXML> NoteXMLList = new List<ClsExportNotesXML>();



//// /////////////////////////////////////////////////////


//// if (TreeMailNodes.SelectedNode.Level >= 0)
//// {
//// List<clsExportFolder> folderList = new List<clsExportFolder>();
//// int iCounterForIncrement = TreeMailNodes.Nodes.Count/100;


//// foreach (TreeNode oTree in TreeMailNodes.Nodes)
//// {

//// if (oTree.Checked == false)
//// IterateFoldersXML(oTree, ref folderList, browsefolder.SelectedPath);
//// else if (oTree.Checked == true)
//// IterateFoldersXMLAll(oTree, ref folderList, browsefolder.SelectedPath);

//// TimerTickForRestore.iCounterForRestore += iCounterForIncrement;

//// if (TimerTickForRestore.iCounterForRestore <= 100)
//// {

//// }

//// }


//// }
//}

/*! \fn private void BtnCancel_Click(object sender, EventArgs e)
* \brief function to Cancel Button Click
* \author Unitrends, Inc.
* \date 23 Feb 2011 *
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

private void BtnCancel_Click(object sender, EventArgs e)
{
this.Close();
}

/*! \fn private void IterateFolders(TreeNode oTree, ref List<clsExportFolder> folderList)
* \brief function to Iterate Folder
* \author Unitrends, Inc.
* \date 23 Feb 2011 *
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

private void IterateFolders(TreeNode oTree, ref List<clsExportFolder> folderList)
{

foreach (TreeNode oSubtree in oTree.Nodes)
{

if (oSubtree.Checked == true)
{
clsExportFolder folder1 = new clsExportFolder();
folder1.ExportType = ExportTypeEnum.Full;
string NodeName = "";
string strNodes = oSubtree.FullPath;//TreeMailNodes.SelectedNode.FullPath;
String[] Nodes = strNodes.Split('\\');
//Nodes.Remove(0);


for (int i = 1; i < Nodes.Length; i++)
{

NodeName = NodeName + Nodes[i];
if (i != Nodes.Length - 1)
NodeName = NodeName + "\\";
}
folder1.FolderName = NodeName;
folderList.Add(folder1);
}
else
if (oSubtree.Nodes.Count > 0)
{
IterateFolders(oSubtree, ref folderList);
}

}

}

/*! \fn private void IterateFoldersXML(TreeNode oMainTree, ref List<clsExportFolder> folderList, String strBrowsePath)
* \brief constructor to Iterate Folders XML
* \author Unitrends, Inc.
* \date 23 Feb 2011 *
* \em COPYRIGHT © 2011 Unitrends, Inc.
*/

private void IterateFoldersXML(TreeNode oMainTree, ref List<clsExportFolder> folderList, String strBrowsePath)
{

foreach (TreeNode oSubtree in oMainTree.Nodes)
{

if (oSubtree.Checked == true)
{
clsExportFolder folder1 = new clsExportFolder();
folder1.ExportType = ExportTypeEnum.Full;
string NodeName = "";
string strNodes = oSubtree.FullPath;//TreeMailNodes.SelectedNode.FullPath;
String[] Nodes = strNodes.Split('\\');
//Nodes.Remove(0);


for (int i = 1; i < Nodes.Length; i++)
{

NodeName = NodeName + Nodes[i];
if (i != Nodes.Length - 1)
NodeName = NodeName + "\\";
}
folder1.FolderName = NodeName;
folderList.Add(folder1);

////////////////////////////////////
string RouteFolderName = MailService.GetRouteFolderName(Convert.ToInt64(TreeMailNodes.SelectedNode.Tag));
ClsExportXML ExportXML = new ClsExportXML();
//ExportXML.UserCountXML = 1;
List<ClsExportUserMetaDataForXML> UserListXML = new List<ClsExportUserMetaDataForXML>();
ClsExportUserMetaDataForXML UserXML = new ClsExportUserMetaDataForXML();
UserXML.ExportTypeXML = ExportTypeEnumXML.Selected;
UserXML.UserNameXML = RouteFolderName;
List<ClsExportFolderXML> folderListXML = new List<ClsExportFolderXML>();
ClsExportFolderXML folderXML1 = new ClsExportFolderXML();
folderXML1.ExportTypeXML = ExportTypeEnumXML.Selected;
folderXML1.FolderNameXML = NodeName;
List<ClsExportMailXML> MailXMLList = new List<ClsExportMailXML>();
List<ClsExportTaskXML> TaskXMLList = new List<ClsExportTaskXML>();
List<ClsExportContactXML> ContactXMLList = new List<ClsExportContactXML>();
List<ClsExportJournalXML> JournalXMLList = new List<ClsExportJournalXML>();
List<ClsExportCalendarXML> CalendarXMLList = new List<ClsExportCalendarXML>();
List<ClsExportNotesXML> NoteXMLList = new List<ClsExportNotesXML>();




////////////////////////////////////
String subQuery = "";
String SearchQuery = "";

if (oSubtree.Text == "Calendar")
{
subQuery = "dbo.AppointmentMaster";
List<AppointmentDetailDTO> AppList = new List<AppointmentDetailDTO>();

if (oSubtree.Level > 0)
//If ROute Folder has been selected
SearchQuery = "Select * from " + subQuery + " where SubFolderId=" + oSubtree.Tag;
else
//If Sub Folder has been selected
SearchQuery = "Select * from " + subQuery + " where RouteFolderId=" + oSubtree.Tag;

AppList.AddRange(MailService.GetAppointmentDetailByCondition(SearchQuery));

//(Temp);

foreach (TreeNode oTree in oSubtree.Nodes)
{
List<AppointmentDetailDTO> Temp;

if (oSubtree.Level > 0)
//If ROute Folder has been selected
SearchQuery = "Select * from " + subQuery + " where SubFolderId=" + oTree.Tag /* TreeMailNodes.SelectedNode.Tag*/;
else
//If Sub Folder has been selected
SearchQuery = "Select * from " + subQuery + " where RouteFolderId=" + oTree.Tag /*TreeMailNodes.SelectedNode.Tag*/;

Temp = MailService.GetAppointmentDetailByCondition(SearchQuery);

AppList.AddRange(Temp);
}

for (int i = 0; i < AppList.Count; i++)
{

ClsExportCalendarXML caleXML1 = new ClsExportCalendarXML();

caleXML1.SentDate = Convert.ToDateTime(AppList[i].CreationTime);
caleXML1.Subject = Convert.ToString(AppList[i].Subject);
caleXML1.Location = Convert.ToString(AppList[i].Location);
caleXML1.StartDate = Convert.ToDateTime(AppList[i].StartTimeUTC);
caleXML1.EndDate = Convert.ToDateTime(AppList[i].EndTimeUTC);
caleXML1.Body = Convert.ToString(AppList[i].Body);
caleXML1.RecuranceState = Convert.ToString(AppList[i].RecurrenceState);

CalendarXMLList.Add(caleXML1);

folderXML1.CalendarListXML = CalendarXMLList;
folderListXML.Add(folderXML1);
UserXML.FolderListXML = folderListXML;
UserListXML.Add(UserXML);
ExportXML.UserListXML = UserListXML;
ClsExportCreateXMLForXML XMLCreaterXML = new ClsExportCreateXMLForXML();
XMLCreaterXML.CreateXMLForXML(ExportXML, strBrowsePath);
CalendarXMLList.Clear();
folderListXML.Clear();
UserListXML.Clear();

}
AppList.Clear();

}
else if (oSubtree.Text == "Contacts")
{
subQuery = "dbo.ContactMaster";
List<ContactDetailDTO> ContactList = new List<ContactDetailDTO>();

if (oSubtree.Level > 0)
//If ROute Folder has been selected
SearchQuery = "Select * from " + subQuery + " where SubFolderId=" + oSubtree.Tag;
else
//If Sub Folder has been selected
SearchQuery = "Select * from " + subQuery + " where RouteFolderId=" + oSubtree.Tag;

ContactList.AddRange(MailService.GetContactDetailByCondition(SearchQuery));

//(Temp);

foreach (TreeNode oTree in oSubtree.Nodes)
{
List<ContactDetailDTO> Temp;

if (oSubtree.Level > 0)
//If ROute Folder has been selected
SearchQuery = "Select * from " + subQuery + " where SubFolderId=" + oTree.Tag /* oSubtree.Tag*/;
else
//If Sub Folder has been selected
SearchQuery = "Select * from " + subQuery + " where RouteFolderId=" + oTree.Tag /*oSubtree.Tag*/;

Temp = MailService.GetContactDetailByCondition(SearchQuery);

ContactList.AddRange(Temp);
}

for (int i = 0; i < ContactList.Count; i++)
{

ClsExportContactXML contXML1 = new ClsExportContactXML();
// contXML1.SentDate = Convert.ToDateTime(dtgContact.Rows[i].Cells["CreationTime"].Value);
contXML1.EmailID = Convert.ToString(ContactList[i].Email1Address);
contXML1.Name = Convert.ToString(ContactList[i].FullName);
contXML1.Companies = Convert.ToString(ContactList[i].Companies);
contXML1.BusinessAddress = Convert.ToString(ContactList[i].BusinessAddress);
contXML1.Mobile = Convert.ToString(ContactList[i].MobileTelephoneNumber);
ContactXMLList.Add(contXML1);


folderXML1.ContactListXML = ContactXMLList;
folderListXML.Add(folderXML1);
UserXML.FolderListXML = folderListXML;
UserListXML.Add(UserXML);
ExportXML.UserListXML = UserListXML;
ClsExportCreateXMLForXML XMLCreaterXML = new ClsExportCreateXMLForXML();
XMLCreaterXML.CreateXMLForXML(ExportXML, strBrowsePath);
ContactXMLList.Clear();
folderListXML.Clear();
UserListXML.Clear();

}
ContactList.Clear();
}
else if (oSubtree.Text == "Journal")
{
subQuery = "dbo.JournalMaster";
List<JournalDetailDTO> JournalList = new List<JournalDetailDTO>();

if (oSubtree.Level > 0)
//If ROute Folder has been selected
SearchQuery = "Select * from " + subQuery + " where SubFolderId=" + oSubtree.Tag;
else
//If Sub Folder has been selected
SearchQuery = "Select * from " + subQuery + " where RouteFolderId=" + oSubtree.Tag;

JournalList.AddRange(MailService.GetJournalDetailByCondition(SearchQuery));

//(Temp);

foreach (TreeNode oTree in oSubtree.Nodes)
{
List<JournalDetailDTO> Temp;

if (oSubtree.Level > 0)
//If ROute Folder has been selected
SearchQuery = "Select * from " + subQuery + " where SubFolderId=" + oTree.Tag /* oSubtree.Tag*/;
else
//If Sub Folder has been selected
SearchQuery = "Select * from " + subQuery + " where RouteFolderId=" + oTree.Tag /*oSubtree.Tag*/;

Temp = MailService.GetJournalDetailByCondition(SearchQuery);

JournalList.AddRange(Temp);
}

for (int i = 0; i < JournalList.Count; i++)
{


ClsExportJournalXML jourXML1 = new ClsExportJournalXML();
jourXML1.SentDate = Convert.ToDateTime(JournalList[i].CreationTime);
jourXML1.Subject = Convert.ToString(JournalList[i].Subject);
jourXML1.Companies = Convert.ToString(JournalList[i].Companies);
jourXML1.StartDate = Convert.ToDateTime(JournalList[i].Start);
jourXML1.Body = Convert.ToString(JournalList[i].Body);
jourXML1.Duration = Convert.ToInt32(JournalList[i].Duration);

JournalXMLList.Add(jourXML1);

folderXML1.JournalListXML = JournalXMLList;
folderListXML.Add(folderXML1);
UserXML.FolderListXML = folderListXML;
UserListXM

Thanks And Regards.
Kamlesh Nikam
Author: Narayanan             
Posted Date: July 19, 2011     Points: 20   


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend