i have this problem, i created an application that play videos but this video haven't extension , so per example i have video like
big_buck_bunny
instead a file like :
big_buck_bunny.mp4
I cant convert this video.
There is a way to play a video from remote without extension?
I have a url like :
D:\\Software\\Marmotta\\marmotta-home\\resources\\88\\95\\43\\big_buck_bunny
Thanks all for help
What about adding the extension at the end of the file?
String path = "D:\\Software\\Marmotta\\marmotta-home\\resources\\88\\95\\43\\big_buck_bunny";
path += #".mp4";
You can use Directory.GetFiles to get all files in a folder filtered to your filename. Be sure to include using System.IO; at thte top of the file.
var path = "D:\\Software\\Marmotta\\marmotta-home\\resources\\88\\95\\43\\big_buck_bunny"
var directory = Path.GetDirectoryName(path);
var filename = Path.GetFileName(path);
string[] files = Directory.GetFiles(directory, filename + ".*", SearchOption.TopDirectoryOnly);
the array files will hold a list of all the files in the folder that started with the name big_buck_bunny, one of those files will be the one you want to use.
Related
I am trying to upload a file with the sendkeys function on the inputid.
I am currently using the path C:\Users\myusername\Documents\seleniumsolution\Utils\Dir\Dir1\Dir2\Dir3\UploadFolder\example.jpg
I see the file in my solution. But I dont want to give to complete path but only the filename and that selenium finds the path itself. Otherwise I will be the only one that can use this testcase.
I tried with:
var file = Path.Combine(Directory.GetCurrentDirectory(), url);
And tried with:
string documents = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath),"UploadFolder");
Both of them dont give me the required result.
Hope that you guys can help me out.
You might need to travel on the folders tree to get to the file
AppDomain.CurrentDomain.BaseDirectory
will get you in the bin\debug folder. From there you can use parent to move up to the file location. For example (might need some tweaking)
string solutionParentDirectory = Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.Parent.FullName;
string file = Path.Combine(solutionParentDirectory, #"UploadFolder\example.jpg");
You can also try
string file = Path.GetFullPath("example.jpg");
I've found a few related questions but they're not working that well. The image name is a modified GUID like 3c6b4a9b-8e88-4c8e-93da-258acd2c964f_0 but the extension isn't known (.jpg, .gif, ..etc). The GUID will be coming from a gridview so it's not a static string. Below is what I have but I'm having a difficult time getting the path to work correctly.
string fileName = `3c6b4a9b-8e88-4c8e-93da-258acd2c964f`;
DirectoryInfo filePath = new DirectoryInfo(#"/Images");
MessageBox.Show(filePath.ToString());
FileInfo[] fileArray = filePath.GetFiles(fileName + "_0.*");
Keep getting issues with the directory being invalid. Currently the files are stored on my c: drive.
How can I get the relative path without hardcoding it in? I was using DirectoryInfo(Server.MapPath("Images")); which worked temporarily then started giving this error System.ArgumentException: Second path fragment must not be a drive or UNC name. which seems to be from the path having the drive "C:" This doesn't seem to be a permanent solution once the site is launched though.
The actual path is C:\Website\Name\Images\3c6b4a9b-8e88-4c8e-93da-258acd2c964f_0.jpg
Thanks!
You've used filePath as the first parameter to GetFiles, just use the wildcard and invoke the overload of GetFiles with one parameter.
filePath.GetFiles("_0.*");
The problem is that you are getting DirectoryInfo for "C:\Images".
You want to use Server.MapPath to get the physical path to the folder that is in your website (which could be anywhere on any drive).
Using the ~ means to start from the root of the running website.
So this should do the trick:
string fileName = `3c6b4a9b-8e88-4c8e-93da-258acd2c964f`;
DirectoryInfo filePath = new DirectoryInfo(Server.MapPath("~/Images"));
FileInfo[] fileArray = filePath.GetFiles(fileName + "_0.*");
I want to exclude some format files like PDB, XML and BMP files in my zip package.
Please help me on this http://cakebuild.net/api/Cake.Common.IO/ZipAliases/B6C83EAE.
Note the built in Zip aliases will only create a standard Zip file not 7zip, if it's only assemblies you want to include in your archive you can use the Zip(DirectoryPath rootPath, FilePath outputPath, string pattern) overload.
Example usage:
Zip("./", "dllfiles.zip", "./*.dll");
If you have several different file types, then I would recommend you create a directory with the artifacts you want to archive and then just zip that directory.
Another way is to use linq in the cakebuild, script. Something along these lines:
var ignoredExts = new string[] { ".bmp", ".xml", ".pdb" };
var files = GetFiles("./bin/Release/*.*")
.Where(f => !ignoredExts.Contains(f.GetExtension().ToLower()));
Zip("./", "cakeassemblies.zip", files);
I already know how to browse for an image using open file dialog. So let's say we already got the path :
string imagePath = "Desktop/Images/SampleImage.jpg";
I want to copy that file, into my application folder :
string appFolderPath = "SampleApp/Images/";
How to copy the given image to the appFolderPath programmatically?
Thank you.
You could do something like this:
var path = Path.Combine(
System.AppDomain.CurrentDomain.BaseDirectory,
"Images",
fileName);
File.Copy(imagePath, path);
where fileName is the actual name of the file only (including the extension).
UPDATE: the Path.Combine method will cleanly combine strings into a well-formed path. For example, if one of the strings does have a backslash and the other doesn't it won't matter; they are combined appropriately.
The System.AppDomain.CurrentDomain.BaseDirectory, per MSDN, does the following:
Gets the base directory that the assembly resolver uses to probe for assemblies.
That's going to be the executable path you're running in; so the path in the end (and let's assume fileName is test.txt) would be:
{path_to_exe}\Images\test.txt
string path="Source imagepath";
File.Copy(System.AppDomain.CurrentDomain.BaseDirectory+"\\Images", path);
\ System.AppDomain.CurrentDomain.BaseDirectory is to provide path of the application folder
I have some problems with relative paths and reproduction of wav files. I have this simple code which works perfectly:
SoundPlayer player = new SoundPlayer();
player.SoundLocation = #"C:\Users\Admin\Documents\Visual Studio 2012\Projects\TestProject\TestProject\Data\Sounds\car.wav";
player.Play();
I want somehow to play that file with relative path but I didn't have success with this:
SoundPlayer player = new SoundPlayer();
player.SoundLocation = #"Data\Sounds\car.wav";
player.Play();
Thank you!
Is Data directory in the root directory of your application? Are you copying the directory contents as output?
If so, did you mean, Data\Sounds\car.wav?
Which, if running from Visual Studio would be in [projectroot]\[release]\bin\Data\Sounds\car.wav
If you don't see this directory in your bin folder, you'll need to ensure you're selecting all of the files you want copied to your output directory (which will copy the directory structure). You can do this by clicking on the file in your project and selecting the file as output.
Get the full path of your file with Path.GetFullPath("relativ/path")
You might be better off using absolute path after all. You can get the root path from the exe file, then append your relative path to it.
Like this:
// getting root path
string rootLocation = typeof(Program).Assembly.Location;
// appending sound location
string fullPathToSound = Path.Combine(rootLocation, #"Data\Sounds\car.wav");
player.SoundLocation = fullPathToSound;
//WindowsFormsApplication4.exe is name of name space this file name found in Debug file
//you should copy your "sound.wav" into your Debug file
string x = (Assembly.GetEntryAssembly().Location + "");
x = x.Replace("WindowsFormsApplication4.exe", "sound.wav");
SoundPlayer player1 = new SoundPlayer(x);
player1.Play();
This is worked for me
System.Media.SoundPlayer player1 = new System.Media.SoundPlayer(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + #"\1.wav");