Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
is there any possibility to play audio-files with spaces in their names?
For instance: Calvin Harris - Summer.mp3
I want to open that file in the Windows Media Player/VLC Media Player and then the error log in the VLC shows: "Bad File descriptor in C:\..Project\Release\Calvin"
Problem: The spaces!
CalvinHarris-Summer.mp3 can be opened without problems.
How could I solve that problem without renaming the audiofiles?
I'm starting the audiofile and the player with a Process.Start
If you pass the file name as an argument to the process with quotes around it, this should work for both VLC/WMP when there are blanks in the file name.
For example.
string fileIn = #"c:\Wherever\Calvin Harris - Summer.mp3";
ProcessStartInfo processStartInfo = new ProcessStartInfo()
{
Arguments = String.Format("\"{0}\"", fileIn),
FileName = VLC_EXE_PATH
};
Process.Start(processStartInfo);
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm doing a program that create and read .txt files, this function OpenFile should open a selected file but this error appeared. What can I do to the program have authorized access?
void OpenFile()
{
openFileDialog1.ShowDialog();
FileInfo info = new FileInfo(openFileDialog1.FileName);
string directory = info.DirectoryName;
StreamReader str = new StreamReader(directory);
string read = str.ReadLine();
LoadScreenWithText(read);
}
System.UnauthorizedAccessException: Access to the path 'C:\NotePad' was denied'
Im assuming that you are getting and absolute file path in this property "openFileDialog1.FileName"
Try running you program using "Run as administrator" by right clicking on EXE .If you are debugging it with visual studio run VS as an administrator .
Note :Good practice is to always check that whether the file exist or not before further proceeding
Use:
openFileDialog1.ShowDialog();
if(File.Exists(openFileDialog1.FileName){
//Your rest of the code
}
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
My project is not finding files that definitely exist. I am using the Stanford NLP library and was getting file not found exceptions which I began debugging.
Here is my test code:
String jarRoot = #"stanford-corenlp-full-2016-10-31\stanford-corenlp-full-2016-10-31\stanford-corenlp-3.7.0-models\edu\stanford\nlp\models\pos-tagger\english-left3words\";
foreach (String fName in Directory.GetFiles(jarRoot))
{
Console.WriteLine("File in jarRoot: " + fName);
Console.WriteLine("File exists? " + File.Exists(fName));
}
The output:
File in jarRoot: stanford-corenlp-full-2016-10-31\stanford-corenlp-full-2016-10-31\stanford-corenlp-3.7.0-models\edu\stanford\nlp\models\pos-tagger\english-left3words\english-left3words-distsim.tagger
File exists? False
File in jarRoot: stanford-corenlp-full-2016-10-31\stanford-corenlp-full-2016-10-31\stanford-corenlp-3.7.0-models\edu\stanford\nlp\models\pos-tagger\english-left3words\english-left3words-distsim.tagger.props
File exists? False
How could File.Exists() possibly be returning false?
Screenshots of directory:
This was sorted out in the comments of the question. Opening the file using a FileStream threw a 'System.IO.PathTooLongException' exception. File.Exists() simply returns false if it encounters any errors such as file path being too long.
#Abbas provided this link that fixed the issue and may be helpful:
Why does System.IO.File.Exists(string path) return false?
Thanks everyone!
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have an .exe application that opens another .exe application in a different folder, which then executes a .bat file to compile a .tex document.
If the initial .exe application is in a different file to the .tex document it can not find it, but if it is in the same folder it runs perfectly.
Any way I can solve this issue? I need to be able to run the initial .exe from a different folder.
If you are calling batch file using Process class, dont forget to set WorkingDirectory property, otherwise it will use your executable` location as default path.
var process = new System.Diagnostics.Process();
process.StartInfo.FileName = #"D:\Dir\Run.bat";
process.StartInfo.WorkingDirectory = #"D:\Dir";
process.Start();
If you use System.Diagnostics.Process.Start you can specify the folder in which to run the batch file.
System.Diagnosis.Process
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I'm having an issue in saving an rtf file, I'm saving it in a subfolder in "MyDocuments" the strange this is that i also save a .bin file and some other stuff and it doesn't causes any exeption, i'am pc admin so why does it happen?
string docs = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Monitor\\Immobili\\";`
richTextBox1.SaveFile(docs+code);
code is also another string
An UnauthorizedAccessException means one of 3 things:
The caller does not have the required permission.
Path is a directory.
Path specified a read-only file.
Check for last two reasons. I think you are not adding filename after path. Add breakpoints and check if richTextBox1.SaveFile(docs+code); is getting the complete path to the file instead of just folder path.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Hi
I am trying to read a plain text file named "test.txt" from my system but all the attempts
File.Exists(), StreamReder are not getting the file, that is not a new task for me but i am irritated due to this strange behavior. I have given full permissions to the file but in vain. I am doing the test in a C# console application. The system has a fresh installation and I am wondering of any permission issue when run in debug mode. I also copied the file to Debug folder but still same error. Can anyone please guide me about this? Thanks in advance
There is a neat function in C# for reading string files: (in System.IO namespace)
string text = File.ReadAllText("test.txt");
If you are having trouble with the path, you can add test.txt as a resource with copy to (add the file to teh project, right-click properties and select Copy to output directory.
Then you can use:
string path = Path.Combine(Directory.GetCurrentDirectory(), "test.txt");
File.ReadAllText(path);
Have you stepped through the code? The first step is to make sure the path being used in the program is correct.
Debug mode will still run under your account so, if you have permission to open the file, that won't be a problem.