BlogEngine.NET Folder Configuration for Uploaded Images - blogengine.net

Is there a configuration setting in BlogEngine.NET that allows me to have images, documents, etc.. go to a specific folder(s)? Currently, it creates folders based on Year, Month, Day of when the file is uploaded.

As of version 2.9 There is not a setting for specifying this path. The path is calculated in the following function in Admin/Posts/Add_Entry.aspx.cs. See the line var dirName = ...
protected void BtnUploadImageClick(object sender, EventArgs e)
{
var dirName = string.Format("/{0}/{1}", DateTime.Now.ToString("yyyy"), DateTime.Now.ToString("MM"));
var dir = BlogService.GetDirectory(dirName);
var file = BlogService.UploadFile(txtUploadImage.PostedFile.InputStream, txtUploadImage.FileName, dir, true);
txtContent.Text += string.Format("<img src=\"{0}image.axd?picture={1}\" />", Utils.RelativeWebRoot, Server.UrlEncode(file.AsImage.FilePath));
txtRawContent.Text += string.Format("<img src=\"{0}image.axd?picture={1}\" />", Utils.RelativeWebRoot, Server.UrlEncode(file.AsImage.FilePath));
}

Related

AIML bot cannot find config folder in Xamarin.Forms

I'm creating a Xamarin.Forms application and I'm trying to implement an AIML bot based on this tutorial: https://www.effacestudios.com/how-to-create-artificial-intelligence-chatbot/. I've added all the references and I've added a config and aiml folder into my directory. This is the code for when a button is clicked:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
private void Button_Clicked(object sender, EventArgs e)
{
string settingsPath = Path.Combine(Environment.CurrentDirectory, Path.Combine("config", "Settings.xml"));
string otherPath = #"C:/Users/PAVILION/Desktop/AimlTest/AimlTest/AimlTest/bin/Debug/netstandard2.0/config/Settings.xml";
Bot AI = new Bot();
AI.loadSettings(otherPath);
AI.loadAIMLFromFiles();
AI.isAcceptingUserInput = false;
User myuser = new User("User1", AI);
AI.isAcceptingUserInput = true;
Request r = new Request(UserEntry.Text, myuser, AI);
Result res = AI.Chat(r);
BotEntry.Text = "Tutorial Bot: " + res.Output;
}
}
Any time I input text into the Entry and tap the button I get an Unable to find specified file on the loadSettings();. I believe the function is looking for a Settings.xml and even though I've directed it to the exact file it still cannot be found. Any help is appreciated.
You need to decompile aiml dll and then change loadsetting path to constant environment.specialfolder.loadapplication.
make sure you have placed your all required file there first.

sub folder in not creating on azure in asp.net mvc5 application

I am ruing my website on azure, every folder is present on site directory in azure but uploadimages is my sub folder of content is absent from wwwroot, and images is not uploading also
I am using
var path =Path.Combine(Server.MapPath("~/Content/UploadImages/")+filename);
same with document upload
According to your description, I have tested on my side, please follow below to find out whether it could help you.
As you said, you got the target file path by this code:
var path = Path.Combine(Server.MapPath("~/Content/UploadImages/") + filename);
Before uploading files, please make sure that the directory in your web server “~/Content/UploadImages/” is existed.
Here is my test code:
MVC controller method
[HttpPost]
public JsonResult UploadFiles()
{
try
{
foreach (string file in Request.Files)
{
var fileContent = Request.Files[file];
if (fileContent != null && fileContent.ContentLength > 0)
{
var stream = fileContent.InputStream;
var fileName = Path.GetFileName(fileContent.FileName);
string baseDir = Server.MapPath("~/Content/UploadImages/");
if (!Directory.Exists(baseDir))
Directory.CreateDirectory(baseDir);
var path = Path.Combine(baseDir, fileName);
using (var fileStream = System.IO.File.Create(path))
{
stream.CopyTo(fileStream);
}
}
}
}
catch (Exception e)
{
return Json(new
{
Flag = false,
Message = string.Format("File Uploaded failed with exception:{0}", e.Message)
});
}
return Json(new
{
Flag = true,
Message = "File uploaded successfully!"
});
}
Additionally, for long-term consideration, you could store your files on Azure Blob Storage which could bring you some benefits, such as:
1.Serving images or documents directly to a browser
2.Storing files for distributed access
3.When you scale up your site, your site could run in multiple Web Server instances which could access the same files & docs simultaneously
For more details, please refer to this link: https://azure.microsoft.com/en-us/documentation/articles/storage-dotnet-how-to-use-blobs/

WP7: Get image's name which images are stored in Libary picture?

I have some images that are stored in Media Libary, view here. Now I need to get the name of an image after I choose the image by using photo chooser task. I used photo chooser task to select an image and then got the path of the image. My pupose is get the name from the path:
private void button1_Click(object sender, RoutedEventArgs e)
{
PhotoChooserTask objPhotoChooser = new PhotoChooserTask();
objPhotoChooser.Completed += new EventHandler<PhotoResult>(PhotoChooseCall);
objPhotoChooser.Show();
}
void PhotoChooseCall(object sender, PhotoResult e)
{
switch (e.TaskResult)
{
case TaskResult.OK:
BinaryReader objReader = new BinaryReader(e.ChosenPhoto);
image1.Source = new BitmapImage(new Uri(e.OriginalFileName));
MessageBox.Show("Photo's name: " + e.OriginalFileName.ToString());
break;
case TaskResult.Cancel:
MessageBox.Show("Cancelled");
break;
case TaskResult.None:
MessageBox.Show("Nothing Entered");
break;
}
}
Output:
Photo's name: \Applications\Data\C80566AB-E17E-495C-81A1-3FCAE34D3DEDE\Data\PlatformData\PhotoChooser-a8208960-3597-40fc-9b4f-869afcf822b6.jpg
After I choose the same image. The name of it will change (PhotoChooser-a8208960-3597-40fc-9b4f-869afcf822b6.jpg will change). I think it's not the name of the photo.
So:
Can we get the name of the image?
And how do we do?
You can get the actual file names. Use the MediaLibrary for that:
MediaLibrary lib = new MediaLibrary();
var collection = lib.RootPictureAlbum;
foreach (var p in collection.Albums[0].Pictures)
Debug.WriteLine(p.Name);
Notice that I am specifying the album index inside the root picture album. 0 will be for sample pictures, and so on. If you need to grab the contents of the image, just use p.GetImage(); to get the readable stream.
No. You cannot get the name of the file as it is in the pictures hub. You are given a copy of the stream and that has a different, temporary, name.

NotifyFilter of FileSystemWatcher not working

I have a windows service (and verified the code by creating a similar WinForms application) where the NotifyFilter doesn't work. As soon as I remove that line of code, the service works fine and I can see the event-handler fire in the WinForms application.
All I'm doing is dropping a text file into the input directory for the FileSystemWatcher to kick off the watcher_FileChanged delegate. When I have the _watcher.NotifyFilter = NotifyFilters.CreationTime; in there, it doesn't work. When I pull it out, it works fine.
Can anyone tell me if I'm doing something wrong with this filter?
Here is the FSW code for the OnStart event.
protected override void OnStart(string[] args)
{
_watcher = new FileSystemWatcher(#"C:\Projects\Data\Test1");
_watcher.Created += new FileSystemEventHandler(watcher_FileChanged);
_watcher.NotifyFilter = NotifyFilters.CreationTime;
_watcher.IncludeSubdirectories = false;
_watcher.EnableRaisingEvents = true;
_watcher.Error += new ErrorEventHandler(OnError);
}
private void watcher_FileChanged(object sender, FileSystemEventArgs e)
{
// Folder with new files - one or more files
string folder = #"C:\Projects\Data\Test1";
System.Console.WriteLine(#"C:\Projects\Data\Test1");
//Console.ReadKey(true);
// Folder to delete old files - one or more files
string output = #"C:\Temp\Test1\";
System.Console.WriteLine(#"C:\Temp\Test1\");
//Console.ReadKey(true);
// Create name to call new zip file by date
string outputFilename = Path.Combine(output, string.Format("Archive{0}.zip", DateTime.Now.ToString("MMddyyyy")));
System.Console.WriteLine(outputFilename);
//Console.ReadKey(true);
// Save new files into a zip file
using (ZipFile zip = new ZipFile())
{
// Add all files in directory
foreach (var file in Directory.GetFiles(folder))
{
zip.AddFile(file);
}
// Save to output filename
zip.Save(outputFilename);
}
DirectoryInfo source = new DirectoryInfo(output);
// Get info of each file into the output directory to see whether or not to delete
foreach (FileInfo fi in source.GetFiles())
{
if (fi.CreationTime < DateTime.Now.AddDays(-1))
fi.Delete();
}
}
I've been having trouble with this behavior too. If you step through the code (and if you look at MSDN documenation, you'll find that NotifyFilter starts off with a default value of:
NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite
So when you say .NotifyFilter = NotifyFilters.CreationTime, you're wiping out those other values, which explains the difference in behavior. I'm not sure why NotifyFilters.CreationTime is not catching the new file... seems like it should, shouldn't it!
You can probably just use the default value for NotifyFilter if it's working for you. If you want to add NotifyFilters.CreationTime, I'd recommend doing something like this to add the new value and not replace the existing ones:
_watcher.NotifyFilter = _watcher.NotifyFilter | NotifyFilters.CreationTime;
I know this is an old post but File Creation time is not always reliable. I came across a problem where a Log file was being moved to an archive folder and a new file of the same name was created in it's place however the file creation date did not change, in fact the meta data was retained from the previous file (the one that was moved to the archive) .
Windows has this cache on certain attributes of a file, file creation date is included. You can read the article on here: https://support.microsoft.com/en-us/kb/172190.

Saving multiple images into isolated storage with wp7

my codes are able to work for saving 1 image into the isolated storage in windows phone 7 but how to change it so that it able to save more than 1 images into the isolated storage.For now, whenever i wanted to save a new image the newest image will overlap the old image so anyone could help me to change my code or with sample that works.Thanks alot
My code :
private void saveButtonClick(object sender, RoutedEventArgs e)
{
try
{
using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (isf.FileExists("myImage.jpg"))
isf.DeleteFile("myImage.jpg");
using (IsolatedStorageFileStream isfs = isf.CreateFile("myImage.jpg"))
{
var bmp = new WriteableBitmap(myImageElement, myImageElement.RenderTransform);
bmp.SaveJpeg(isfs, bmp.PixelWidth, bmp.PixelHeight, 0, 100);
}
}
}
catch (Exception exc)
{
MessageBox.Show(exc.Message);
}
}
YOur files are being overwritten as you're giving each one the same name.
If you want multiple files they'll need to have unique names. Do this by removing the hardcoded name in your code and using appropriate/unique names for each file.

Resources