I am using the Mailkit for .net and am having trouble to delete a IMAP-folder that I created by Code. This is my sample code:
Created the folder like this:
var personal = Program.Client.GetFolder (Program.Client.PersonalNamespaces[0]);
var mailkit = personal.Create("mailkit", false);
var archive = mailkit.Create("archive", true);
var flagged = mailkit.Create("flagged", true);
...
Tried to delete the Folder again like this:
var temp = Program.Client.GetFolder("mailkit");
temp.Delete();
Get an FolderNotFoundException, but the folder is still there?
Need a little help or tip how to do ...
(Sorry for this bad english :))
Program.Client.GetFolder("mailkit"); is throwing a FolderNotFoundException because the folder doesn't exist. You need to provide the full path of the folder to ImapClient.GetFolder(string path), but instead you have only provided the folder's name.
Here's how to get the "mailkit" folder:
var personal = Program.Client.GetFolder (Program.Client.PersonalNamespaces[0]);
var mailkit = personal.GetSubfolder ("mailkit");
Related
I have a solution I created a little over a year ago that uses PnP.Core to upload file to a specific folder on SharePoint. It was all well until a couple days ago where that solution started generating error that says
To update this folder, go to the channel in Microsoft Teams
I am at a bit of a loss as to why and what is causing this.
Below is a minimal code sample of what I have. I should mention that the folder is getting created but fails with said error when uploading the file to the folder.
Any pointers would be greatly appreciated.
authenticate using officeDev.PnP.Core.AuthenticationManager
...
Folder Root_Folder = web.GetFolderByServerRelativeUrl(Root_Folder_Relative_Url_Path);
//Create new subFolder to load files into
string Folder_Name = _Folder_Name;
Root_Folder.Folders.Add(Folder_Name);
Root_Folder.Update();
//Add file to new Folder
Folder Subject_Folder = web.GetFolderByServerRelativeUrl(Root_Folder_Relative_Url_Path + "/" + Folder_Name);
FileCreationInformation Subject_Result_File = new FileCreationInformation {
ContentStream = new MemoryStream(_File_To_Upload),
Url = _File_Name,
Overwrite = true
};
Microsoft.SharePoint.Client.File uploadFile = Subject_Folder.Files.Add(Subject_Result_File);
Subject_Folder.Update();
Client_Ctx.ExecuteQuery();
Looks like the Update method was the issue. Removing it and just letting the ExecuteQuery handle all the operation fixed it.
I received a link to shared folder from e-commerce company. The link is public and not shared with my dropbox account directly.
How do I get an url to the image that I can pass to either DownloadAsync method of the same sdk or simply HttpClient and well ... download it?
Ideally it would be the same link I get when I click on the image when viewing that shared folder in a browser.
https://www.dropbox.com/sh/{folder_hash}/{file_hash_maybe}/{filename}?dl=0
This is what I have tried:
using Dropbox.Api;
using Dropbox.Api.Files;
...
var accessToken = "abracadabra";
var sharedFolderUrl = "https://www.dropbox.com/sh/{folder_hash}?dl=0";
using (var dbx = new DropboxClient(accessToken))
{
var sharedLink = new SharedLink(sharedFolderUrl);
var sharedFiles = await dbx.Files.ListFolderAsync(path: "", sharedLink: sharedLink);
// sharedFiles - has over 13,000 entries, I use cursor to get them all.
foreach (var file in sharedFiles.Entries)
{
if (file.IsFile)
{
// tried this, but:
// 1. it's crazy to loop through all
// 2. link.Response.Url gives me the same url to a shared folder for all items
var link = await dbx.Sharing.GetSharedLinkFileAsync(url: sharedFolderUrl, path: "/" + file.Name);
}
}
}
Using the GetSharedLinkFileAsync method is the right way to programmatically download a file from a shared link. It actually gives both the metadata (in the link.Response in your code like you mentioned), as well as the file data directly (not via a URL).
To access the file data, you can use any of the GetContentAs... methods documented under IDownloadResponse as returned by GetSharedLinkFileAsync. In your code, that would look something like: link.GetContentAsStreamAsync() (or whichever one you want).
Alternatively, if you want to download the entire folder from the shared link, you can use the URL parameters documented in this help center article. (That may fail for very large folders though.)
I have an app wheere the user can view images attached to a sample, and then they need to be able to email the details of that sample (including image attachements) to stakeholders.
In my web.config of the web app, I have:
<add key="ImagesPath" value="~/Images" />
And this path seems to work perfectly for retrieving and displaying the images, which are stored in an images folder in the project.
However, when I try adding the image as attachments to an email (from a shared library) The app suddenly can't find the path with this error when calling
message.Attachments.Add(new Attachment(item));
when debugging
Could not find file 'C:\Program Files (x86)\IIS Express\~\Images\3000\1\1\3.png'.
after publishing
Could not find a part of the path 'C:\Windows\SysWOW64\inetsrv\~\Images\9251\1\1\1.JPG'.
What I tried
1.
I tried calling this before creating the attachment
var appDomain = System.AppDomain.CurrentDomain;
var basePath = appDomain.RelativeSearchPath ?? appDomain.BaseDirectory;
var p = Path.Combine(basePath, item);
message.Attachments.Add(new Attachment(p));
But the app still can't find the files.
I tried calling
System.Web.HttpContext.Current.Server.MapPath(item);
message.Attachments.Add(new Attachment(item));
before creating each attachment, but again theh images can't be found.
Can anyone please help me resolve this.
From the code you posted, you seems to call the System.Web.HttpContext.Current.Server.MapPath(item); method, but not using the result of that to create the Attachment.
The Server.MapPath returns the physical location of the file. Use the result of the call to that method to add the attachment.
This should work.
var item = "3000/1/1/3.png";
var fileLocation = Path.Combine("images/",item);
var fullPath = System.Web.HttpContext.Current.Server.MapPath(fileLocation);
message.Attachments.Add(new Attachment(fullPath));
Sometimes, I tend to do a file exist check before actually trying to access it.
if (File.Exists(fullPath ))
{
message.Attachments.Add(new Attachment(fullPath));
}
If you are using it from an MVC controller, you may use Url.Content along with Server.MapPath
var p = Server.MapPath(Url.Content("~/images/3000/1/1/3.png"));
I have this piece of code:
string jsonPath = #"Model\Datamodel\UserData.json";
User userItem = JsonConvert.DeserializeObject<User>(user);
User.Add(userItem);
string content = user;
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await folder.GetFileAsync(jsonPath);
await FileIO.WriteTextAsync(file,content);
Debug.WriteLine(String.Format("DONE"));
The "Done" debug line is written in console but it does not write anything to the file.
I also don't get any errors. When I debug and look at Folder and file I see that they are correctly.
Can anybody help?
You can't write to files in Windows.ApplicationModel.Package.Current.InstalledLocation, you need to use one of the other writeable locations available to you instead. (e.g. ApplicationData.Current.LocalFolder)
If you need to access the content of the file that was shipped with the package, I would suggest copying it to the local folder, and using the copy for read/write access.
I'm creating a simple app for windows 8 that writes me a xml file to documents library.
The problem is when i'm save the file, it saves it on skydrive and i want to save it on c:\Users\pc-name\Documents. I'm using KnownFolders.DocumentsLibrary and updated the manifest to save xml files too, otherwise i couldn't save any file in it.
public static async void XmlSaveFreeChallenge(Challenge currentChallenge)
{
var challenge = new XElement("Challenge");
var docSave = new XDocument(challenge);
challenge.Add(new XAttribute("Name", currentChallenge.Template));
var pontos = new XElement("Type", currentChallenge.Type);
docSave.Descendants("Challenge").FirstOrDefault().Add(pontos);
var folder = KnownFolders.DocumentsLibrary;
var outputStream = await folder.OpenStreamForWriteAsync("CaiMUfiles\\output\\Desafios\\" + currentChallenge.Template + ".xml", CreationCollisionOption.ReplaceExisting);
var ms = new MemoryStream();
docSave.Save(outputStream, SaveOptions.None);
await ms.CopyToAsync(outputStream);
}
The user gets to choose where the Documents library points. See the following option: settings charm -> Change PC Settings -> SkyDrive -> Save documents to SkyDrive by default
I'm not sure if it's possible for your app to override the user's choice there. Even if it is possible, it's probably better to respect the user's choice.
What Isaac McGarvey said is correct nevertheless there might by something that you can do. i did not found a way how to programmatically switch default saving folder for libraries but you still have access to all folders that is included in libraries. The only think is that you need to know absolute path so if you can save the path before then you can use this to get desired folder :
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync("AbsolutePath");
and then you can start enumerating creating or whatever you need. The problem is that if you use for example
List<StorageFolder> folder = await KnownFolders.DocumentsLibrary.GetFoldersAsync();
you wont get folder for Documents and folder for SkyDrive and folder for other linked folders to libraries you will just get all folders that is inside all of these folders in one list which mean you cannot choose where to save file.
I hope this helps a bit.