Changing a file on the server using a local windows app - c#

I am writing an automation to update the contents on an excel sheet(in c#) present on our server. Our server has various portals and has different credentials. How could I fetch the file on my portal to my local computer to make some changes to it.

Is your computer on a domain with the server? If so...
Run as a user who has access and manipulate it via UNC paths just like normal paths... for example you would load #"\Servername\share\file.xls" instead of #"C:\path\file.xls".

Related

Can't save data in SQL Server database, where to place the file?

In my application I need to use a local database (the application I'm creating works with everything locally). I had one database that worked really bad, because sometimes it saved the data and other times don't. And if I published the program I couldn't find the database file.
But I am having some trouble to know where to place the database. I have created one in E:\PAP\Trabalhos\Trabalhos\database.mdf and other in E:\PAP\Trabalhos\Trabalhos\bin\Debug\database.mdf, but in any of those paths the database is recreated/goes back to the previous state, when I try to start the program.
In my connection string I have this:
Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|database.mdf; Integrated Security=True
and that points to the file ...\bin\debug\database.mdf
I want to be able to access the database in any computer I use the program and be able to actually save data.
Where is the recommended path to place the database file and be able to access it independent of the computer I am using?
Should I use Windows authentication or SQL Server authentication?
tl/dr: Database doesn't save data and I want to be able to access it in any computer without any extra steps.
You can't use "(LocalDB)\" and access it from any computer. LocalDB is by design accessible only from the applications running on the same computer (it is an embedded database).
To access database over the network you need to install instance of SQL Server, like full SQL Server Express instance or use some cloud service like AWS or Azure.

How to get the local desktop path of the users file when the application is hosted from server?

I am trying to run a macro-file that will be present in users desktop via my .net website, hence I would like to know how I can get the path of that macro file in my code and open it.
I am currently using following described code to get the path, and I think that this must be trying to take the path from server computer but I would like to get this from users computer, this particular macro file will open internet explorer and navigate to certain website and download a report to local computer hence I would like this to be run from users side.
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Is it possible to get the path automatically or should i get that from user.
please provide suggestion.
You are hosting a website, which is using a web server like IIS and the user access the site using a browser like edge, chrome, now the file is in user desktop, so the main question remains,
Does the browser process have the access to the file system of the user
Mostly no, especially not via the call Environment.GetFolderPath(Environment.SpecialFolder.Desktop);, this will be good for running it on hosted sever, where w3p.exe process is accessing the file system with required permissions
For the end user desktop
You need to provide the file dialog box, let user select the file / directory and need to plan to serialize the file to the sever (upload) for doing any processing. You can binary serialize the file using a provider like protobuf, msgpack to achieve the necessary functionality
Code you have provided, is good for for the process where you have direct control, like Console, WPF, which runs on the system under certain permission and thus access the file system for processing

Access to a MDB file without the file system access in ASP .Net

I have an input MDB file coming from a third party program. I have to read it in my asp .net application and then ask some related form to the final user.
At the moment, I can write the mdb file on the filesystem and read it, it works but sometimes this feature doesn't work and I have to restart the server.
The customer want to externalize the server and I can't write to the file system or even restart it so I'd like to read the mdb file in asp .net from a MemoryStream or maybe execute a conversion to a most readable format like XML, but I don't think it is possible.
So I'm looking for a solution to preprocess the access file.
I don't think it is possible to read it via javascript (only vbscript).
The only way I imagined is :
call a special application with a url code like app://id the id is transmitted to a special application on the desktop, he will select his file and the content will be transmitted to the web app via web service
after that the person should click on a button and he can process the different form associated with that data
that sounds me complicated for the final user
does someone have some feeling or idea about that case ?
Edit
The mdb file is uploaded via a http form contained into the web form.
Sometimes, after the upload, the application throw an exception and it can't use the c:\windows\temp. I have an error : Access not possible on the specified file.
I don't have a better information because the application is located in the internal network of the customer and I'm not there. So I have to ask them to reboot it.
Quote: Configuring Permissions for an Access Database
When a Web application uses an Access database, the application must
have Read permission to the .mdb file so the application can access
the data. Additionally, the application must have Write permission to
the folder that contains the .mdb file. Write permission is required
because Access creates an additional file that has the extension .ldb
in which it maintains information about database locks for concurrent
users. The .ldb file is created at run time. [...]
Therefore, to use an Access database in an ASP.NET Web application,
you must configure the folder that contains the Access database to
have both Read and Write permissions for the local ASPNET user
account.
In other words, if you have no permissions to read and write you will not be able to work with .mdb.
There are following options available
If permissions cannot be done due to security reasons, but your web server has an access to the .mdb file location (both located in same network) then your client could setup a scheduled job which will backup/copy .mdb to another location where asp.net could have permissions to work with .mdb. This however will be a problem for syncing backup .mdb to production .mdb.
Setup a webservice to update .mdb. It will be hosted on the server where .mdb is located and will have all required permissions. Your application will work with .mdb through the webservice and does not require any permissions on .mdb.
Replace .mdb with SQL Server Express

C# - Remote Access to Text File

I would like to access/read a text file that resides on a remote windows server. The local computer and the remote server are not connected to each other i.e. they are not part of a network or under a domain. Is there any possible way, using C#, to access and read the contents of that text file?
P.S.: The remote server requires a username and a password to log on to it. I'm the server admin and thereby I am aware of those credentials.
Thank you in advance!
C# is a programming language. You could implement a Windows service application that will listen to connections and then dump the contents of anything you'd like. There is nothing natively implemented in C#, however, that will allow you to immediately do what you're asking.
As long as both machines have internet access, and the network they're on will allow outside connections past the firewall, there are some examples online that will get you heading in the right direction. Example.
Be wary, however, that if you implement your own server application that will host files over the internet, you will have to also implement your own credential checking mechanism. Even if your server requires authentication, that will have no affect on your server application.
Hello and thanks for the replies! I have exposed the contents of the remote text file using a RESTful service. The local computer can now use the data stored in that text file by just navigating to the url where the service output is returned.

Access Database on server, installing an applicaiton that uses access database

1) I am developing a desktop application that connects to a access database to store some information. This access database is on a server. I can get to that server using FTP sequence. The server also has the capability to establish connection to access database. Right now, my application downloads the database file into a folder on the computer edits it and puts it back on the server. I would really love to know if its possible to connect to the access database, make changes to it all without downloading it so that I can save time.
2) If its not possible to do what I was asking for in question 1. Say, I share my application with my colleges and I want them to be able to do the same with the database editing. after I make an .exe file out of my project and send it to them. Do they need to install ACE.oledb.12 on every computer that I want to run it on?
As Access is a file based system rather than a dedicated database server, "remote connections" don't exactly exist as all data processing has to be done locally. However as long as you are able to setup either a VPN to the server where the Access file is stored, or even better map the path as a network drive then you should be able to access it without having to download the file first. If you only have FTP access though then it wouldn't be possible.
If all you are using is Jet/ACE, the database that Access normally uses, the other users will at least have to have the drivers, which are free, or if you are working within Access itself, you will need the runtime, also free.
Actually, your terminology you using is wrong. You don't connect to a word file. You don't connect to a power point file.
So you have to keep in mind here you are not really connecting to some text file or mdb file that just happens to be sitting on a hard drive.
You are thus simply opening a file.
I mean it is silly to say we connect to a word file, or we connect to a Power point file. So in the case of the office suite and those basic simple files that resides on the disk drive?
We are talking about plane Jane windows file.
A horse is a horse is a horse.
A file is a file is a file.
So you don't connect to the jpg file sitting on the hard drive, you OPEN the jpg file. So if you talking about your current setup it best to use the correct terminology here. You are not connecting to that Access accDB file, but are in fact opening a PLANE JANE windows file. If you look close at your connection string, it will ALWAYS have a fully qualified windows path name in it that resolves to a file sitting on a folder.
So if you place that file on some server, say web server, then then you still faced with having to open that windows file. This is NOT ANY different than wanting to open a power point file. That means if you going to connect over the internet then you need to EXTEND the windows file system (this means you will need some kind of VPN). At the end of the day, if you cannot use windows networking to browse and open the folder where that file resides, then you cannot open that file with Access (or more specific in your case the JET data engine).
So for example, if the server where the file resides is a non windows box, say Linux, then you need to "add or use" or "install" the windows file and networking system on that box. A common choice in Linux is to install and run Samba on that computer.
Keep in mind that in the case of using SQL server, then you are connecting to a SERVICE running ON THAT server. In this case then you not opening a file on the remote box, but are simply are using a socket (TCP/IP) connection to some service. So you not just opening a silly old windows file that happens to be an accdb file on that system in this case.
So as such when you use FTP or http, these are not real "windows" networking systems that allow you to open + use a plane Jane windows file.
FTP will require the WHOLE FILE to be downloaded local.
PROBLEM!
If the web site or web server has the accDB file open, then how are you going to have the web server CLOSE the file BEFORE you upload and OVERWRITE the file? In other words, if that file is open by the web server, then you should NOT be making a copy and even downloading a copy via FTP until the SERVER AND WEB SITE CLOSES THE FILE! This means you NEED permission to STOP the web server while you do this!
So as such, just keep in mind the concept here that you are NOT connecting to some file, but you are just going to OPEN the file. You need to be able to OPEN the file, and you need to be using the windows networking system to do this open file in the case of Access. I mean, you don't have to install Access(JET) on the target computer. You don't have to install Power Point on the target computer to open a power point file.
You don't have to install word on that system to open a word file.
You don't have to install Excel on that system to open an Excel file.
So you are ONLY opening a file that just happens to be on some other computer.
So the Access database engine and software MUST be installed on your computer (no .exe possible here). You can most certainly package up your application as an installable windows application that then can be installed on each computer. So a free edition of the Access runtime is available, but you still going to have to install that free version of Access on computers that use Access, even if it is the free runtime edition. However, these days, I not really aware of any popular development system that produces just .exe files without requiring a runtime of some kind, be it .net, VB6, Java, or in this case Access – so some kind of support and runtime files are quite much a common requirement in most systems in use today.
So, just keep in mind you are opening a plane Jane windows file.
As such, your path name of http, or FTP is not a allowed windows path name and is not a windows file/networking system. As such a path name has nothing to do with windows networking and opening of a simple file sitting on the hard disk. So HTTP or FTP etc. are not based on windows networking and file system.
I don’t think this basic concept is too hard to grasp, but at the end of the day the concept you need to grasp and learn is that when you open a windows file sitting in a folder on the hard drive, then then will you need the windows file system to open such files. The idea and concept of opening a file in a folder might be new to you, but it is a basic requirement and understanding you need to solve this issue.
As noted, you can consider a VPN, but I explain why such a setup is not going to work in this article:
Using a wan with ms-access? How fast, how far?
http://www.kallal.ca/Wan/Wans.html
(do read the above – as it explains that you CAN open such files over the internet, but ALSO explains that such connections are WAY TOO SLOW! – remember high speed internet is WAY TOO SLOW here for this use!).
I suppose another possibility would be to consider the new web publishing ability that Access has. In the following video note how I switch to running the Access application 100% in the browser. The resulting application does not need any ActiveX or Silverlight. So the web pages run + work fine on my smartphone and even my iPad.
http://www.youtube.com/watch?v=AU4mH0jPntI
So you can use the new web publishing feature, and that would allow one to use http: to use the application

Categories

Resources