I am trying to read the emails that are being moved to the clutter folder by outlook. The below code works fine for other folders, but when I try to open the clutter folder the code defaults to the error message indicate the folder does not exist.
oApp = new Microsoft.Office.Interop.Outlook.Application();
oNS = (Microsoft.Office.Interop.Outlook._NameSpace)oApp.GetNamespace("MAPI");
oNS.Logon(null, null, false, false);
oFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
string folderName = "Clutter";
try
{
oSubfolder = oFolder.Folders[folderName];
for (int i = 1; i <= oSubfolder.Items.Count; i++)
{
item = (Microsoft.Office.Interop.Outlook.PostItem)oFolder.Items[i];
}
}
catch
{
MessageBox.Show("There is no folder named " + folderName +
".", "Find Folder Name");
}
You are assuming Clutter is the child of the Inbox folder. It is Inbox's peer:
oFolder = (Outlook.MAPIFolder)oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).Parent;
Related
I have tried the below code to create a folder structure in Test Plan using OTA, but unable to do so.. I am getting message saying Node not found.. Please help me out with the proper code
Folderpath = Subject\UAT\UAT2\Testcases
private void Upload_Test_Click(object sender, EventArgs e)
{
if (File_path.Text == null)
{
MetroMessageBox.Show(this, "Please Select a Valid File", "File", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
string path = File_path.Text;
FileInfo fileinfo = new FileInfo(path);
ExcelPackage excel = new ExcelPackage(fileinfo);
var worksheet = excel.Workbook.Worksheets["Test Cases"];
//get te number of rows and columns in the sheet
int rows = worksheet.Dimension.Rows;
int columns = worksheet.Dimension.Columns;
int i = 2;
//loop through the worksheet rows and columsn
while (i <= rows)
{
testfact = (ITestFactory2)LoginForm.qctd.TestFactory;
TreeManager treemgr = LoginForm.qctd.TreeManager;
SysTreeNode tstrr = treemgr.NodeByPath[worksheet.Cells[i, 1].Value.ToString()];
tstrr.AddNode(worksheet.Cells[i, 2].Value.ToString());
tstrr.Post();
tstrr.Refresh();
List testlist = tstrr.NewList();
foreach(Test tset in testlist)
{
tset["TS_NAME"] = worksheet.Cells[i, 2].Value.ToString();
tset.Post();
tset.Refresh();
}
i = i + 1;
}
MessageBox.Show("Test Uplaoded successfully");
}
It would be helpful if you added more details about the error (like the row where it happens). I assume you are getting it while calling treemgr.NodeByPath and means that there is no folder with such path - check you ALM folders or adjust your script so it creates missing folders
I am trying to create a new folder within a document library. Actually, the code works well, but when the title of the new folder starts with a blank, I get an exception "File not found" and the folder is not created.
I already tried to encode the title: replaced the blach by "%20" and by "+". In this case the folder is created, but it contains other characters like"+" at the first position in the title.
I tried to create the folder " blankBefore" in the SharePoint application by using the browser - and it works. The folder is create and looks like this " blankBefore".
I can create folders with a blank in the title, but not, if the title of the folder starts with a blank.
public bool CreateFolder(SharePointNode spParentNode, string strFolderName)
{
ClientContext localCTX = new ClientContext(spParentNode.ParentSite);
ConectClient(localCTX);
Folder newFolder = null;
var folder = localCTX.Web.GetFolderByServerRelativeUrl(spParentNode.URL);
localCTX.Load(folder);
localCTX.Load(folder.Folders);
Folder newFolder = folder.Folders.Add(strFolderName);
newFolder.Update();
localCTX.ExecuteQuery();
return true;
}
Create folder in SharePoint list (SharePoint 2010, 2013, 2016)
using (var clientContext = new ClientContext("http://sp/sites/test"))
{
string folderName = "test";
var list = clientContext.Web.Lists.GetByTitle("ListBase");
list.EnableFolderCreation = true;
clientContext.Load(list);
clientContext.Load(list.RootFolder);
clientContext.Load(list.RootFolder.Folders);
clientContext.ExecuteQuery();
var folderCollection = list.RootFolder.Folders;
foreach (var folder in folderCollection)
{
if (folder.Name == folderName)
{
clientContext.Load(folder.Files);
clientContext.ExecuteQuery();
}
else
{
var itemCreateInfo = new ListItemCreationInformation
{
UnderlyingObjectType = FileSystemObjectType.Folder,
LeafName = folderName
};
var newItem = list.AddItem(itemCreateInfo);
newItem["Title"] = folderName;
newItem.Update();
clientContext.ExecuteQuery();
break;
}
}
}
I am trying to connect to a remote server and access a specific directory in that server for searching a file but for some reason it shows that the directory doesnt exist on the server even though it actually exists. I am guessing that my file path is wrong. Can anyone please suggest me if I made a syntax error?
filepath = #"\\172.17.20.11\E$\MessageLogs\" + logType + "\\" + country + "\\" + year + "\\" + month + "\\" + day + "\\";
private void GetFiles(string filePath)
{
try
{
tblFileContent = new DataTable();
getColumns(tblFileContent);
//C:\MessageLogs\ElmaCore\KENYA\2016\March\22
//filePath = #"C:\MessageLogs\"+filePath; //Pick a folder on your machine to store the uploaded files
if (!Directory.Exists(filePath))
{
fn.MessageLine(this.Page, "Log folder does not exist.", System.Drawing.Color.Red, "lblMessageLine");
dtDate.Focus();
return;
}
string searchReference = txtReference.Text.Trim();
//string filePath = System.Configuration.ConfigurationManager.AppSettings["InFolder"].ToString();
DirectoryInfo DirInfo = new DirectoryInfo(filePath);
FileInfo[] CsvFiles = DirInfo.GetFiles("*" + searchReference + "*.log").OrderByDescending(p => p.LastWriteTime).ToArray();
if (CsvFiles.Length > 0)
{
foreach (var file in CsvFiles)
{
string FileName = file.Name;
string sourceFile = System.IO.Path.Combine(filePath, FileName);
ProcessFile(FileName, sourceFile);
}
//LoadGrid();
}
else {
fn.MessageLine(this.Page, "Sorry, No files found for the specified reference.", System.Drawing.Color.Red, "lblMessageLine");
txtReference.Focus();
return;
}
}
catch (Exception ex)
{
fn.MessageLine(this.Page, "Sorry an Error Occured. Please try again", System.Drawing.Color.Red, "lblMessageLine");
ErrLogger.LogError("filelog-" + ex.Message); //oledbconn.Close();
return;
}
}
As you say your directory exists than it might the problem with permission.
Please make sure account under which code is been running have permission to that folder.
Also note that once you deploy in IIS, change identity of apppool to a domain user who has permission.
If you want to verify if its permission problem, than just do this.
Right click into that folder and give permission to everyone and test.
I'm trying to create a tree view to search for a directories in a remote server using FTP/SFTP connections, What I'm trying to do is start filling the tree view with all the available directories starting with the home directory such as the following example:
Home---->SubFolder
|
|---->Another Folder
|
|---->MyOtherFolder
Then when the user start clicking in each folder it start to display their subdirectories from the tree view as the follwoing example (clicking in Another Folder):
Home ---->SubFolder
|
|---->Another Folder -------> MyFolder1
| | -------> MyFolder2
|
|---->MyOtherFolder
I'm trying to get those folders but it's throwing an exception, also it is gathering files, not folders....
this is the code that I have....
private void FillTree()
{
SessionOptions SessionOptions = new SessionOptions();
Session MySession = new Session();
SessionOptions.HostName = InterfaceValues[0];
SessionOptions.UserName = InterfaceValues[2];
SessionOptions.Password = InterfaceValues[3];
SessionOptions.PortNumber = Convert.ToInt32(InterfaceValues[1]);
if (string.Compare(InterfaceValues[9], "FTP", true) == 0)
SessionOptions.Protocol = WinSCP.Protocol.Ftp;
else if (string.Compare(InterfaceValues[9], "SFTP", true) == 0)
{
SessionOptions.Protocol = WinSCP.Protocol.Sftp;
SessionOptions.SshPrivateKeyPath = InterfaceValues[12];
SessionOptions.SshHostKeyFingerprint = InterfaceValues[10];
}
try
{
MySession.Open(SessionOptions);
foreach (RemoteFileInfo info in MySession.EnumerateRemoteFiles("/", "*", EnumerationOptions.AllDirectories))
{
if (info.IsDirectory)
tvRemoteDirectory.Nodes.Add(info.Name);
}
MySession.Close();
}
catch (Exception ex)
{
MySession.Close();
MessageBox.Show("Not possible to connect to " + InterfaceValues[0] + "\nError Message: " + ex.Message);
this.Close();
}
The exception that I'm getting is:
{WinSCP.SessionRemoteException: Error listing directory '/jpm_icl'. ---> WinSCP.SessionRemoteException: Permission denied.
Error code: 3
Error message from server: Permission Denied!
Any idea what could I do at this point?
What I did was this:
ListDirectory function to retrieve all the directories, as I don't want the directory "." and "." I have to exclude it.
RemoteDirectoryInfo RemoteDirectory;
if (RemoteDirectoryPath != "Home")
RemoteDirectory = MySession.ListDirectory(RemoteDirectoryPath);
else
RemoteDirectory = MySession.ListDirectory("/");
if (tvRemoteDirectory.SelectedNode.Nodes.Count > 0) tvRemoteDirectory.SelectedNode.Nodes.Clear();
foreach (RemoteFileInfo fileinfo in RemoteDirectory.Files)
{
if (fileinfo.IsDirectory)
{
if (fileinfo.Name != "." &&
fileinfo.Name != "..")
{
TreeNode ChildNode = new TreeNode();
ChildNode.Text = fileinfo.Name;
ChildNode.ImageIndex = 0;
tvRemoteDirectory.SelectedNode.Nodes.Add(ChildNode);
tvRemoteDirectory.ExpandAll();
}
}
}
since a few days I'm trying to rename the sent mail folder, deleted elements and the inbox folder via c#.
I've tryed something like this:
List<Outlook.MailItem> mailItems = new List<Outlook.MailItem>();
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace outlookNs = app.GetNamespace("MAPI");
// Add PST file (Outlook Data File) to Default Profile
outlookNs.AddStore(pstFilePath);
Outlook.MAPIFolder rootFolder = outlookNs.Stores[pstName].GetRootFolder();
Outlook.Folders subFolders = rootFolder.Folders;
foreach (Outlook.Folder folder in subFolders)
{
folder.Name = (folder.Name == "deleted Elements"?"deleted":folder.Name);
}
But without success. I always get the exceptiion that I do not have permissions to change the name. Other custom created folders I'm able to rename without any problems.
Is there something to do to unlock the folder?
Or is there an other possibility to access the folders?
Thanks a lot
Edit: The Expetion is: You do not have permissions.
public string RenameFolder(string name, string folderid)
{
Outlook.Application app = new Outlook.Application();
Outlook.NameSpace ns = null;
Outlook.Folder folder = null;
string n= null;
try
{
ns = app.GetNamespace("MAPI");
folder = ns.GetFolderFromID(folderid) as Outlook.Folder;
n=folder.Name;
folder.Name = (folder.Name = name) ;
return n + " has been successfully changed to " + folder.Name;
}
catch (System.Exception ex)
{
throw ex;
}
finally
{
if (app != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(app);
}
if (folder != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(folder);
}
if (ns != null)
{
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(ns);
}
}
}
this code is working for me..when i run visual studio in administator mode..