I'm wondering if anyone has come across this issue or knows of a better way to do this with GoDaddy as the web host?
First off I'll say this code works just fine when I run it locally. It's only when I put it out on a GoDaddy site that is causes an error. The idea behind the code is that I want to look at a "Galleries" folder and inside of that main folder I have folders like "Completed" and "Current". This is where the end user will put different folders underneath those. I then get all of those subfolders into a List which I use to create a as hyperlinks. Those hyperlinks will get all the files in that folder and display them in an image gallery.
Again, it works just fine locally but when I put it on GoDaddy I get an error like "Could not find a part of the path 'G:\PleskVhosts\websitename\httpdocs\aaw\Galleries\Current".
Doing some troubleshooting, if I just do the first directory it works fine on GoDaddy. It's not until I add a second or more that I get the above error. I'm stumped as to why I would get this since they are all in their own variables and Lists.
Here is a sample of the code. If I only use the first DirectoryInfo then all is good. It's not until I add the second one that the issue arises.
DirectoryInfo dirComplete = new DirectoryInfo(HostingEnvironment.MapPath("/Galleries/Completed/"));
DirectoryInfo[] completedFolderList = dirComplete.GetDirectories();
var completedFolders = new List<Gallery>();
foreach (var folder in completedFolderList)
{
var gallery = new Gallery();
gallery.GalleryName = folder.Name;
completedFolders.Add(gallery);
}
DirectoryInfo dirCurrent = new DirectoryInfo(HostingEnvironment.MapPath("/Galleries/Current/"));
DirectoryInfo[] currentFolderList = dirCurrent.GetDirectories();
var currentFolders = new List<Gallery>();
foreach (var folder in currentFolderList)
{
var gallery = new Gallery();
gallery.GalleryName = folder.Name;
currentFolders.Add(gallery);
}
var vm = new GalleriesViewModel();
vm.CompletedGalleries = completedFolders;
vm.CurrentGalleries = currentFolders;
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 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'm trying to get a specific application base ASP.NET Temp folder. I know we can use HttpRuntime.CodegenDir property to get the actual temp asp folder that the application is writing to. Is there any way I can get location to the base folder for that application in C#? Example:
<server>\c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\<AppName>
For any other who stumble on this question,
I couldnt find any direct way to get it. the way i resolved this is to get executing assembly location using below line
Assembly.GetExecutingAssembly().Location;
And then get to the parent folder which is the application name recursively using
var dir = new DirectoryInfo(path);
while (dir.Parent.Name != folderName)
{
dir = dir.Parent;
}
return dir.Parent.FullName;
which will give me the required path im looking for.
I'm trying to use the Duplicati API to restore a single file.
About the Scenario: The whole thing runs on linux so it is compiled with mono. My backup contains two source Folders, so if I run Interface.ListSourceFolders() I get an Array of two.
Desired result: I want to restore one single file (or Folder) from my backup
Current result: If I run the code below it restores all the backed up files (so Folder 1 and Folder 2) into the path in //Comment1.
List<string> files = new List<string>();
files.Add("path"); //Comment1
Dictionary<string,string> options = new Dictionary<string,string>();
options["passphrase"] = MySettings.Password;
options["restore-time"] = date;
//Comment2
Interface i = new Interface("file:///path/to/archives", options);
string result = i.Restore(files.ToArray());
What I tried: I tried to set the path at //Comment1 to the absolute path (/desired/file/to/restore) or using the index of the source Folder (0/file/to/restore) and I also played around at //Comment2. e.g. I added something like options["restore-path"] = "/path/to/restore". I always get the same result.
Does anyone see what I'm doing wrong? Because I don't know what else I could try. There is almost no documentation so I don't know where to search. If someone knows a link for a good documentation I would be happy too!
In case if someone is interested. After trying around for hours I finally found out how to restore just a single file or folder. Here is what I'm doing now:
List<string> files = new List<string>();
files.Add("/restore/path"); //Comment1
Dictionary<string,string> options = new Dictionary<string,string>();
options["passphrase"] = MySettings.Password;
options["restore-time"] = date;
options["file-to-restore"] = "files"; //Comment2
Interface i = new Interface("file:///path/to/archives", options);
string result = i.Restore(files.ToArray());
At //Comment1 you need to set the desired restore path. In this folder all backup-set-folders are created (The folders from Interface.ListSourceFolders())
At //Comment2 you can specify the files to be restored in this form: 0/file/to/restore where 0 is the index of the source folder (Interface.ListSourceFolders()). If you need to restore multiple files you can do it by combining them into one string: e.g. Windows: 0/file1;1/file2 or Linux 0/file1:1/file2 (The difference is semicolon or colon)
Now there is just one more thing: You can not restore a folder with its files. You need to combine all files and sub-files in the string mentioned above.
I hope I could help somebody.
I'm trying to build a metro-app which shall load an image file from another computer in the same homegroup (all computers use windows 8 x64 with working homegroup). All samples I found do not use subfolders or use the filepicker.
Since all my images are in the same folder and I know their names I do not want to use the filepicker.
I activated "Pictures Library" in the appxmanifest and I can list the directories/computers in the homegroup but I'm stuck in opening files or subfolders.
Here's what I did:
var folder = await Windows.Storage.KnownFolders.HomeGroup.GetFolderAsync("homegroupname");
foreach (var a in await folder.GetFoldersAsync())
{
Debug.WriteLine(a.Name.ToString());
}
This gave me a list of the computers of the homegroup (as expected).
Here's what I tried without success:
folder = await Windows.Storage.KnownFolders.HomeGroup.GetFolderAsync(#"homegroupname\computername");
folder = await folder.GetFolderAsync(#"computername");
These attempts didn't work and I ran out of ideas. Do I have to allow the folder somewhere? Is my way of opening the (sub-)folders the right one?
I did it with the following (nearly intuitive) approach:
I create a CommonFileQuery for files of the right type and choose the one with fitting name.
List<string> fileTypeFilter = new List<string>();
fileTypeFilter.Add(".jpg");
fileTypeFilter.Add(".png");
var queryOptions = new QueryOptions(CommonFileQuery.OrderByDate, fileTypeFilter);
var query = KnownFolders.HomeGroup.CreateFileQueryWithOptions(queryOptions);
IReadOnlyList<StorageFile> fileList = await query.GetFilesAsync();
StorageFile file = fileList.FirstOrDefault(x => x.Name == "123_123.jpg");