I am currently working on a basic chatroom system for my college using text files, allowing everyone to save chatrooms in their area and share them with others. For this to work I need to get the actual directory of each users file on the server and not their local (relative) directory.
My college has a layout of each users E:\ drive being equal to \ServerName\Student\ (StudentNameHere)\
and in the past I have just been using .Replace("E:\","\\ServerName\Student\"+Enviroment.Username +"\")
But upon finding out that my college has different locations such as instead of Student lets say Student1, it makes my code more prone to breaking.
I have tried using
Path.GetFullPath(<File in this Users Directory>);
But it's only returned the path relative to users directory and not to the server, I don't know the type of link they used, but I thought symbolic would be good practice, tho trying this same command again on my own pc which I know has junction links for visual studio source/repos, didn't mention it's true (absolute) path either, any help on this would be much appreciated as this will fix a lot of bugs in my code and hopefully be a clean way to fix it all up as well, Thank You.
Thanks To #KevinGosse (https://stackoverflow.com/users/869621/kevin-gosse)
The problem I was having was Server Based and the link you commented did help, Thank You
I couldn't test this until today because I needed server access but it works like a charm, Thank You.
How do I determine a mapped drive's actual path?
Related
I know there are a bunch of these questions already but none of the ones I found depict the scenario I have.
So what I want to do is to
move a directory via Directory.Move. Both source and destination are on a file server in the same network so both paths are network paths (starting with \\SERVER rather than a drive letter).
The application that‘s supposed to do that gives me an „UnauthorizedException: Access is denied“. Because it‘s confidential I can‘t show the log or code.
But I tried to reproduce it by simply calling Directory.Move via PowerShell ([System.IO.Directory]::Move()). There I receive the same message. Access to path X is denied. Nothing more.
This error appears with any user context. An admin, an admin with „run as admin“, the user of the application and the user of the application with „run as admin“.
Manually moving these directories works without a problem.
Creating a directory with Directory.CreateDirectory works too. But moving the newly created Directory results in the same error.
Executing these commands on the file server works just fine if using the local path. Using the network path (still on the actual fileserver, though) results again in the Acces is denied error.
Could it be, that the issue lies within the path rather than the directory? The permissions are all correct and set (as said, manual operations work). Are there any workarounds?
I really don‘t know what to do. I‘m the only developer at this company and the rest are network engineers and can‘t help
me either.
There are a number of things that could be causing it to deny access and it would be hard to point you in the right direction without seeing your code. But here are 2 scenarios that might help you.
Scenario 1 - The filepath you are using is in the wrong format, Usually I have had a access denied because the format of the network filepath was actually wrong. I would recommend looking up examples of how you should pass the filepath. Also have a talk with your network engineers and ask them about the rights that have been setup for that filepath.
Scenario 2 - You might be passing a filepath when you also need to specify a name. Now I dont have all the details but I also had issues in the past using the Directory.Move function where I actually had to specify a filename to move it to. You do this by just adding the file and extension to the end of the target path to copy to.
If you could post some more information I might be able to point you in the right direction but this is what I can think of for now. I hope this works for you or atleast brings you closer to an answer. Good luck!
*Edit: It looks like I am wrong on the scenarios, Have a look at this link Can you move a file/folder across a network share in .NET?
You will have to first manually create the filepath and then copy all the files into the new filepath you have created. It seems like Directory.Move has problems when different machines are used.
Looking for a quick way of listing all currently installed steam games in c#. I've been using a method of checking the registry at the moment for installed apps, but if the user has their steam games on another hard drive and has swapped it into the machine then they won't be in the registry right?
So Looking for a way. Has anyone got any experience with the SteamAPI to point me in the right way if there is anything in there at all? Or any experience with this sort of thing?
Any help is appreciated.
Thanks.
If you already know the SteamApps directory, you can look at each appmanifest_1010.acf files in that directory. The numbers are the game's appid, and the file contains information about that game including its name and install path.
I work for an IT company where we all carry around flash drives that have our most used programs on them.In my spare time I am hoping to create a "main menu" item that is kind of a fun and convenient way to access these files. I am working on creating this using Visual Studio 2013 and using visual C# windows forms. I have come across a snag however that I can't seem to find a workaround for. I am by no means fluent in C#, but I need to have a button on the windows form open a file without specifying what drive it comes from. I understand that I have to specify a path, but as these will be stored on the flash drives of myself and my coworkers I cannot foresee that the path will always begin with E:. Depending on what USB slot the drive is plugged into it could be N: or F: or the like. I have provided an example below:
Using what I currently know I am opening files using this line of code:
System.Diagnostics.Process.Start("C:/Users/Myname/Desktop/Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
Is there any way possible I can have the file open simply from
System.Diagnostics.Process.Start("Asmodeus/Anti-Virus/Anti-Virus Installers/avast_free_antivirus_setup.exe");
or something of that nature?
Thanks in advance.
There must have been some mis-communication when I asked my question previously. what I am looking to do is open an executable file via a button click on the windows form using a relative path. I am not able to specify the absolute path because the application will be run from a flash drive and therefore will change depending on what USB slot it is currently inserted into.
What I am hoping to accomplish is insert a line of code that will allow me to open an executable file that is located in the \bin\debug folder along with the application itself. I have a picture for clarification but apparently do not have enough reputation to post it. Thank you and sorry for the earlier confusion.
Usually you can just use Environment.GetFolderPath (MSDN) to give you what you need. It doesn't do absolutely everything, but if you need Desktop and the like, that is plenty.
Depending on the target version of .Net, the SpecialFolders exposed are not all there. It may turn out that you need more than they provide, but in your case it doesn't sound like it.
If there is more you need that is not covered in the default, check out this project. I'm sure there are others like it, but it does a little more than the default BCL version, using the API directly. It is at least something to read and learn (and translate from vb.. use an online translator, very quick). I haven't looked at it, but it seems like you are learning this c#/.net thingy, so it might be helpful
This article is about accessing Windows special folders.
These folders include your “Favorites”, “Cookies”, system libraries and the like.
Here is code, including a large number of constant definitions, plus documentation,
allowing access to and creation of these folders.
When I look at my Google Drive online, I see files have the owner listed, sometimes shown as "Shared By" myself or someone else. Is it possible to obtain this value programmatic-ally (using C#)?
Ideally I want to have someone share a file with me, then me do some processing on the file (via a Windows Service), and then me re-upload the file with it's alterations. I would need to know the owner of the file though.
Is this possible? Is this possible without using the Google Drive API? - I'm thinking about using normal .NET/Windows functions to pull the file out of the Google Drive local folder...
File resources returned by the Google Drive API include a userPermission field which lists users authorized to access the document together with their role (owner, reader or writer):
https://developers.google.com/drive/v1/reference/files#resource
I have a similar need. I am thinking of developing an application to process the files shared by users and display them some reports. So, my application needs to uniquely identify the owner so that only he and none other can view the reports for his files.
Looking at the answer given above by Claudio, I debugged in Java to examine the "userPermission" field, but could not find anything of help. I also examined other fields of the file, but got nothing except the name of the owner in string format.
Is there a way it can be achieved? Would need some help. Thank you.
I'm wondering how to get globally unique IDs for files and folders in Windows (XP, Vista and 7), and also be able to get the full path of the file or folder just by having the ID, something like getFileByGUID. I'm trying to do this in C++, C# and PHP.
The globally unique IDs should stay the same even if the file is moved, so using the full path of the file or folder wouldn't work.
Any help would be much appreciated, thanks!
You may consider using the Distributed Link Tracking Service.
Subject to the caveats mentioned in the page for BY_HANDLE_INFORMATION, GetFileInformationByHandle might be helpful, depending on what the goal is.
This won't let one retrieve the file's name, though. Due to NTFS hard links there may be more than one path to the same file contents anyway...
You could hash together information about the file, such as its metadata and/or contents. It would be difficult to do this on an entire file system without collisions, but I assume you're not trying to index the whole file system. This wouldn't work if you need files to retain their IDs if they're modified, though.