Image path error in Tablet device - c#

When creating my project I have referenced the image path as #..\..\Assets\no_picture_available1.gif was working fine, when I installed my application in other machine it says the path not available.
I tried using this one
System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + #"..\..\Assets\no_picture_available1.gif";
It shows the path as
"F:\\WindowsApp\\UI\\bin\\Debug..\\..\\Assets\\no_picture_available1.gif"
How can I set the path to Assets folder?

I found the solution to my issue, problem was with the Assets path,
when debug i set the path as different and while in release mode i set the different path.
string pathdir = Path.Combine(System.Windows.Forms.Application.StartupPath, "Assets\\no_picture_available1.gif");
#if DEBUG
return pathdir = #"../../Assets/no_picture_available1.gif";
#else
return pathdir;
#endif

Related

UnauthorizedAccessException in UWP Directory.CreateDirectory

This is a Unity project building to Hololens 2. I'm trying to create a new folder within the Application.PersistentDataPath but it's failing due to UnauthorizedAccessException. Strange thing is it's been working and only recently with seemingly unrelated changes it stopped.
Here's the function that is failing.
static DirectoryInfo EnsureDirectory(string subFolder)
{
Debug.Log($"starting EnsureDirectory() for {subFolder}.");
string directoryPath = Path.Combine(Application.persistentDataPath, subFolder.ValidatePath());
Debug.Log($"About to create directory {directoryPath}");
var dir = Directory.CreateDirectory(directoryPath);
Debug.Log($"Successfully created directory {dir.FullName}");
return dir;
}
At Directory.CreateDirectory I get the error as follows:
Hololens screenshot of debug log
EXCEPTION: UnauthorizedAccessException: Access to the path "C:\" is denied.
This error only happens when deployed to the device. In the Unity editor it works perfectly. I also don't know why it would say "C:" when that's not the path I'm trying to use.
Any help would be greatly appreciate.
Thank you #aybe for the answer that did the job.
This is probably because it checks for every path segment, starting
with the first one which is root and obviously forbidden. Try new
DirectoryInfo(Application.persistentDataPath).CreateSubdirectory(...);
instead to see if the error vanishes

Selenium C# Mstest - chromedriver.exe does not exist. Getdirectory() referring some-other directory while executing vis mstest commands

when i'm running the selenium test from VS2017 it is able to pick the drivers successfully BUT when i run the same test using mstest command - internally it is referring some other directory!
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\mstest.exe/
testcontainer:..\Test\Sun.TestAutomation.dll /test:"myfristtest"
/resultsfile:..\Test\TestResultLog.trx //Mstest commands
OpenQA.Selenium.DriverServiceNotFoundException: OpenQA.Selenium.DriverServiceNotFoundException: The file
C:\Test\xsed_2018-12-07 10_55_51\Out\chromedriver.exe does not exist.
The driver can be downloaded at
http://chromedriver.storage.googleapis.com/index.html.
code:
this.DriversPath = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory()));
additional information:
drivers are available in debug folder why my mstest is referring the drivers in "Out" folder ??
This post is a bit old but since it was brought back to the the front, this may help someone.
I would download the ChromeDriver Nuget package. This way you always get the latest version.
Right click on your project > properties. Click on Build tab.
set Conditional compilation symbols = _PUBLISH_CHROMEDRIVER
under output path set: bin\Debug\
Once installed, clean solution and rebuild and you should see the file in the bin dir.
for your chromedriver call it should look something like this:
Driver = new ChromeDriver(Path.Combine(GetBasePath, #"bin\debug"), options);
Then add the GetBasePath code:
public static string GetBasePath
{
get
{
var basePath = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
basePath = basePath?.Substring(0, basePath.Length - 10);
return basePath;
}
}
This PC -> Properties -> advanced system settings -> Environment variables -> system variables -> Varible PATH add folder, where you have chromedriver.exe

How to execute command using exe file located at the solution ? C# winforms

How to execute command like:
adb.exe kill-server
for the file located in the solution itself ?
I have executed only after adding the adb to the PATH in environment variables:
private string implementCommandLine(string fileName, string param)
{
string output = "";
ProcessStartInfo startInfo = new ProcessStartInfo(fileName, param)
{
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
Process adbProc;
adbProc = Process.Start(startInfo);
using (StreamReader myOutput = adbProc.StandardOutput)
{
output = myOutput.ReadToEnd();
}
return output;
}
I tried as well to get the path of the adb.exe located in the Files folder
but it is really too confusing to get the path, i couldnt get it successfully !
Still when I execute "Files/adb.exe [params]" I get this error:
An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.dll
Exception Details:
The folders you see in the Solution Explorer are there to organize your source code while you do development. In general, once you've built and deployed your program, those folders don't automatically have any meaning.
What you need to do is to ensure that the file you need to run is part of the build output, where you can know the location of the file relative to your executable ahead of time, and then make sure you deploy it that way. The easiest way to do this is to set the properties on the item of interest:
This will copy the item, intact, into the build output in the same folder structure as in your source code, so in your case your Debug folder would have:
Program.exe Program.pdb Files\adb.exe
Whenever you deploy your build, make sure you maintain that folder structure, and then you can find adb.exe relative to Program.exe using any of the usual ways to get the program's folder path,
First of all: make sure if you went to the options and selected "Copy if newer" or "copy always" for that file.
If that is right be sure to add System.Windows.Forms.Application.StartupPath to the path you want to execute that file.
And third thing is: Are you sure, it is your application (adb) that cannot be found and not some dependency (required dlls for exammple)? Validate this by putting a simple textfile.txt in that directory and try to start it. If that works, but adb does not, than the application is started correctly, but needs other libraries itself, that cannot be found.
Additionally: Show us, what is within your "filename" variable if you are still stuck.

Windows 7 Environment Variable for System32 or SysWOW64

Is there an environment variable to directly access System32 or SysWOW64 folder, respectively, in Windows 7 32bit or 64bit?
I know of a workaround by using %WINDIR%\System32 which is not working for me.
I have to re-compile an EXE that refers to some OCX that should be registered in System32 folder. The problem I am facing is that I have to install it in a 64bit system where the OCX got registered in SysWOW64 folder and not getting registered in System32 folder.
What should I try? Thanks for your help!
Edit:
I figured out that the solution has a reference to a dll which refers to flash10h.ocx. For this flash10h.ocx has to be registered. I could get it registered in SysWOW64 folder but not in System32. My system already has a flash player v11.xx. Will this not work?
Please help!
The following method will retrieve the path to the 32-bit system directory and, optionally, place it in the environment variable SYSDIR32.
public static String Get32BitSystemDirectory (Boolean placeInEnvironmentVariable = true)
{
String sysDir = "";
if (Environment.Is64BitOperatingSystem) sysDir = Environment.ExpandEnvironmentVariables("%windir%\\SysWOW64");
else sysDir = Environment.ExpandEnvironmentVariables("%windir%\\System32");
if (placeInEnvironmentVariable) Environment.SetEnvironmentVariable("SYSDIR32", sysDir, EnvironmentVariableTarget.User);
return sysDir;
}

create folder and copy set of files to local disk

i am trying to create a folder and copy some images into it using c# wpf application.
curName = txt_PoemName.Text;
// Specify a "currently active folder"
string activeDir = #"C:\Program Files\Default Company Name\Setup2\Poems";
//Create a new subfolder under the current active folder
string newPath = System.IO.Path.Combine(activeDir, curName);
// Create the subfolder
System.IO.Directory.CreateDirectory(newPath);
foreach(DictionaryEntry entry in curPoem){
string newFilePath = System.IO.Path.Combine(newPath, entry.Key.ToString() + Path.GetExtension(entry.Value.ToString()));
System.IO.File.Copy(entry.Value.ToString(), newFilePath, true);
}
i have successfully created the folder and images. and also i can access them via application. but i cant see them in the location on my local disk. when i restart the machine , then application also cant see them.how can i solve this?
Sounds like you have encountered UAC Data Redirection
http://blogs.windows.com/windows/b/developers/archive/2009/08/04/user-account-control-data-redirection.aspx
You need to either force the application to run as an administrator.
How do I force my .NET application to run as administrator?
Or not save your data in a sensitive area. I would recommend saving in a subfolder of
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);

Categories

Resources