I've run into a problem using the form Apple Quicktime Control while attempting to pull metadata from m4p files.
I've got an array of strings which hold the filepath of individual files and then I loop through them as follows:
foreach (string file in files)
{
axQTControl1.URL = file;
// Create new movie object
QTOLibrary.QTMovie mov = new QTOLibrary.QTMovie();
mov = axQTControl1.Movie;
string title = mov.get_Annotation((int)QTAnnotationEnum.qtAnnotationFullName);
}
However, I run into the issue that the only real methods I can call from my QTMovie object include get_Dimensions or get_Rectangle.
According to this tutorial, however, I should be able to use get_Annotation to pull the meta data.
I'm having a hard time finding any documentation on this and that tutorial is about the only help I've gotten. If anyone has any idea or a link to get me going in the right direction it would be appreciated.
I've found a solution. This works for m4a and m4p files and probably others but I haven't tested m4b and the like.
using QTOLibrary;
foreach (string file in files)
{
axQTControl1.URL = file;
// Create new movie object
QTOLibrary.QTMovie mov = new QTOLibrary.QTMovie();
mov = axQTControl1.Movie;
string title = mov.Annotation[(int)QTAnnotationsEnum.qtAnnotationFullName];
string artist = mov.Annotation[(int)QTAnnotationsEnum.qtAnnotationArtist];
string album = mov.Annotation[(int)QTAnnotationsEnum.qtAnnotationAlbum];
songs.Add(new Song(title, album, artist, file));
WriteLine("Evaluated " + title);
}
// Make sure the previous file is not in use
// This will prevent an IOException when the file is in use and cannot be moved
axQTControl1.URL = "";
Related
I have read a lot of answers on this issue, but none of them helps for me.
Now, it's been 5 years that I had C# and apperantly I've forgotten it all. But I like to get into the language again to use it for automation. So, here is the bit of code I already have:
{
string path = #"C:\Users\decraiec\Documents\Client Automated";
//In this folder I will find all my XML files that I just want to load in a textbox
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//create a way to read and write the files
//go get the files from my harddrive
StreamReader FileReader = new StreamReader(path);
//make something readable for what you have fetched
StreamWriter FileWriter = new StreamWriter(textBox1.ToString());
int c = 0;
while (c == FileReader.Read())
{
string load = FileReader.ReadToEnd();//read every xmlfile up to the end
string stream = FileWriter.ToString();//make something readable
}
try
{
textBox1.Text = FileWriter.ToString();//what you have made readable, show it in the textbox
FileWriter.Close();
}
finally
{
if (FileReader != null)
{ FileReader.Close(); }
}
if (FileWriter != null)
{ FileWriter.Close(); }
}
}
If I run this code like this I'll get:
An unhandled exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
Additional information: Access to the path 'C:\Users\decraiec\Documents\Atrias Automated' is denied.
While I was hoping to see all the XML files in the textbox listed and clickable ( - although I need to insert the clickable code yet )
I've been looking in my folder and subfolder and files and I do have admin rights on everything. About the [ mscorlib.dll ] I have no clue where to find this.
Now if I wrap the StreamReader in a use ( var....;) VS doesn't recognizes it (red lines under the words) saying that I'm missing an instance of an object or something else of issue (just trying to glue the things together).
Could someone try to get me in the right direction please?
I think your path is a directory, not a file. Almost the exact same issue was addressed here: Question: Using Windows 7, Unauthorized Access Exception when running my application
What you can do is create a DirectoryInfo object on the path and then call GetFiles on it. For example:
DirectoryInfo di = new DirectoryInfo(directoryPath);
Foreach(var file in di.GetFiles())
{
string pathToUseWithStreamReader = file.FullName;
}
You need to use Directory.GetFiles to get any files residing in your "Client Automated" folder, then loop through them and load every single file into the stream.
var files = Directory.GetFiles(path);
foreach (var file in files)
{
var content = File.ReadAllText(file);
}
You can read more on it here:
https://msdn.microsoft.com/en-us/library/07wt70x2(v=vs.110).aspx
Also - in general, when working with files or directories like this, it's a good idea to programmatically check if they exist before working with them. You can do it like so:
if (Directory.Exists(path))
{
...
}
Or with files:
if (File.Exists(path))
{
...
}
I have built a quizz app in C#/xaml that works fine on my computer and would like to port it on windows phone 8.
Here is how it works : I have a two columns .txt file : first column is a country, 2nd is the capital city. The program randomly selects a country and proposes 4 possible answer the user has to choose from.
I managed to port the game on my phone but I can't find how to use my .txt file.
To read the file I've written this method :
static List<Countries> openFile(string fileName)
{
string line = null;
List<string> liste = new List<string>();
List<Countries> countries = new List<Countries>();
using (StreamReader reader = new StreamReader(fileName)) //fileName = "capitals.txt")
{
line = reader.ReadLine();
while (line != null)
{
liste.Add(line);
line = reader.ReadLine();
}
}
foreach (string ttt in countries)
{
string[] test = ttt.Split('\t');
countries.Add(new Countries() { nomPays = test[0], Capitale = test[1] });
}
return countries;
}
My problem is very dumb. I don't know where to put the file on my computer to debug the program, visual studio keeps indicating it can't locate the file.
In the IDE, I tries to find where he is looking the file for. I found it was supposed to be located in a folder somewhere in "appdata\packages\" but when I look for that folder, it does not exist (I have checked that hidden files and folders are displayed).
One thing I tried, was to add the file manually in the assets, but I still can't open it. Maybe am I using the wrong method to open the file ? I've tried different options to open the file, such as :
//get local folder
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
var dataFolder = await local.GetFolderAsync("dataFolder");
var file = await local.OpenStreamForReadAsync("Capitals.txt");
Or :
var uri = new System.Uri("ms-appx:///Assets/Capitals.txt");
var file = Windows.Storage.StorageFile.GetFileFromApplicationUriAsync
But neither work, I keep having a file not found error.
My question is simple : 1/ Where should I put my file on my hard drive while working on the software and 2/ How should I access this file ?
Thank you very much for your help
my requirement is to move files from one directory to another after certain interval. So basic copy works, but during the next subsequent interval I want to move only the new files.
Following is my approach:
I am creating the file list of both source & target directory in target location, the idea is based on the difference of these two files copy only the files that are new from last iteration.
For 1st iteration it will create a blank file in target indicating copy everything. But my file comparison is hitting issues here, based on logic in below code it's creating this excpetion "System.Linq.Enumerable+d__99`1[System.String]"
Here's the code:
static void Main(string[] args)
{
create_source_fileList();
string source_dir = System.Configuration.ConfigurationSettings.AppSettings["SourceDir"];
string target_dir = System.Configuration.ConfigurationSettings.AppSettings["TargetDir"];
string dpath = target_dir + "Diff" + ".txt";
TextWriter df = new StreamWriter(dpath);
DirectoryInfo sourceinfo = new DirectoryInfo(source_dir);
DirectoryInfo targetinfo = new DirectoryInfo(target_dir);
string[] source_f_list = File.ReadAllLines(target_dir + "Source_File_List.txt");
string[] target_f_list = File.ReadAllLines(target_dir + "Target_File_List.txt");
IEnumerable<String> file_list_diff = source_f_list.Except(target_f_list);
df.WriteLine(file_list_diff);
df.Close();
if (!Directory.Exists(targetinfo.FullName))
{
Directory.CreateDirectory(targetinfo.FullName);
}
foreach (FileInfo fi in sourceinfo.GetFiles())
{
fi.CopyTo(Path.Combine(targetinfo.ToString(), fi.Name), true);
}
create_target_fileList();
}
Need help in fixing this issue,also will this approach down the line work in loop where I will iterate only the names in diff file.
Thanks!!
It's not creating an exception; rather, it's writing the result of calling ToString on an IEnumerable<string> instance. You need to replace:
df.WriteLine(file_list_diff);
with
df.WriteLine(string.Join(Environment.NewLine, file_list_diff));
or, prior to .NET 4:
df.WriteLine(string.Join(Environment.NewLine, file_list_diff.ToArray()));
I have MyFile.zip that has a main directory "MyMainFolder", and several SubDirectories inside of that, one of which I want to extract (MySubFolder)...with all of its subdirs and contents.
I am trying to figure out how to 'step-into' the MyMainFolder , so that I can extract 'MySubFolder'.
I have some code that will extract a folder as long as that folder I am looking for exists as the main folder in the zip...and I can detect if the main folder is called "MyMainFolder" so it knows to look inside that and extract from there rather than looking in the main zip root for MySubFolder).
using (ZipFile zip1 = ZipFile.Read(fileName))
{
zipFile = ZipFile.Read(#""+fileName);
var result = zipFile.Any(entry => entry.FileName.Contains("MySubFolder"));
if (result == false)
{
MessageBox.Show("MyMainFolder detected....Extracting from MyMainFolder...");
// something here that will extract JUST MySubFolder and contents
} else {
foreach (var e in selection)
{
var selection = (from e in zip1.Entries where (e.FileName).Contains("NySubfolder") select e)
e.Extract(outputDirectory);
}
}
}
So far, I have tried putting a separate using inside each part of the if-else, and I tried creating a seperate selectionX in which I tried to force the root-folder name (which will always be 'MyMainFolder' for this experiment) to be part of what it looked through, thinking I could then extract MySubFolder, but I couldn't get that to work either. I tried to incorporate several other methods I found on stackflow and elsehwere, like using parts of 'how to extract files, but ignoring the path in the zipfile' and other such posts to try and find a way to 'skip' over that main root folder when extracting. (so that it gets ONLY 'MySubFolder' (and contents) and extracts to outputDirectory (not MyMainFolder\MySubFolder...)
Any help is appreciated.
Thanks!!
Enumerating though the entire contents until I came across what I was looking for worked, but just as an experiment, I wanted to see if it could be done another way.
Since I was unable able to check the names of the subfolders inside a root folder, I figured I could just match what I was looking for as I was parsing through it, extracting only what I wanted to, and then just change the output path.
using (ZipFile zip1 = ZipFile.Read(fileName))
{
zipFile = ZipFile.Read(#""+fileName);
var result = zipFile.Any(entry => entry.FileName.Contains("MySubFolder"));
if (result == false)
{
// something here that will extract JUST MySubFolder and content
string TestX = Path.GetDirectoryName(e.FileName) ;
string MyNewPath = outputDirectory+#"\"+TestX ;
e.Extract(MyNewPath);
} else {
foreach (var e in selection)
{
var selection = (from e in zip1.Entries where (e.FileName).Contains("MySubfolder")
.select e)
e.Extract(outputDirectory);
}
}
Something like that..
Not very useful, but interesting and helped me learn a little.
(if nothing else, an example of how NOT to do things..hehe)
Thanks
I want to create a gallery in asp.net the way it should work is as follows:
iterate through gallery folder
select all the folder and show them as albums with cover pic as thumbnail.jpg in that folder
when clicked on the album it should display the content of the folder (images).
My approach for creating this was to iterate through the folders and make views and link button based on that for albums and to display the content of album in that view as images using repeater control, but that didn't work out as it had many errors while implementing it. and I had to write the whole thing in on_init() function because of dynamic views.I can implement the html and js part (like for light box and other visual stuffs).
Please suggest some better approach maybe with some code example. Please use c# . Thanks
I can not just write you all the code... but ill give you a startup code:
int scanLVL = 4;//or however deep you need to go...
public void GetImageFromDir(string sourceDir, int startLVL)
{
if (startLVL <= scanLVL)
{
// Here you can process files found in the directory.
string[] fileEntries = Directory.GetFiles(sourceDir);
Label_showdata.Text +="<br />Dir:" + Path.GetFileName(sourceDir) ;
foreach (string fileName in fileEntries)
{
// do something with fileName
String tree = "";
for (int i = 0; i < startLVL; i++)
tree += " ";
Label_showdata.Text += "<br />" + tree + Path.GetFileName(fileName);
}
// Going in subdirectories of this directory.
string[] subdirEntries = Directory.GetDirectories(sourceDir);
foreach (string subdir in subdirEntries)
if ((File.GetAttributes(subdir) & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)
GetImageFromDir(subdir, startLVL + 1);
}
}
This will print you on your web page(actualy in that Label_showdata) all the files and the directory where they are.
Basically from here you will need to wrap that data into a table and bind it in whatever control you feel comfortable with... Is not that hard actually... but it takes a bit more time to write exactly all the code (time that unfortunatlly i do not have at the moment...)