I am working with SharePoint 2010. I need to get the data from excel file stored in sharepoint library. I have plans to accomplish this by using OLEDB connection. So I need to download the excel file from doc library and store it in a temporary location and then access this temp file to get data from it. Now my question is which is the best ans safe location to stored the downloaded file? So far I have used SharePoint's layouts directory, C:windows:TEMP and even Path.GetTempFileName(). But the result I get this is " ACCESS DENIED!". Any ideas in temporary location? Is there any other location which is safe?
Thanks
Check whether you are running the file saving code with Run with elevated privileges and the app pool account has write access to the provided path. It's not a good practice to store temp files inside 14 hive.
Why don't you use Excel Web services to read the excel file if your farm has excel services enabled.
Refer http://msdn.microsoft.com/en-us/library/ms500767%28v=office.14%29.aspx
Or else try to use third party libraries like EPPlus where you can open the excel file using a stream rather than from a physical file location.
Related
I did search many times to find a proper solution, but till today I didn't find a proper solution for my function. Target is to open a schedule from the server using VBA either from within MS Project or MS Excel using only part of the mpp filename.
We do have a ProjectID for each schedule. Unfortunately, this is only part of the file name and the rest even changes from time to time:
Example: ProjectID_Department_Projectname
With FileOpenEx I can easily open a file from the server using full file name. I wonder now if there is a way to use part of the name.
-Is there a function to open a file using placeholders?
or alternatively
-Does anyone know how to loop through all files on project server or retrieve a list of files?
I'm not new to Access, but am very new to VBA coding. Our management software is horrible, but it's the best that is available in the industry and I have created many many reports using Access, but have new problem now.
Attachments in the system are stored in one central location and then the file name stored in a SQL table. I have created queries to pull the full file path including the file name. Would it be possible to use some VBA coding to print all the existing PDFs in sequence from the paths returned in the query?
Thank you for any and all help!
Native VBA controls the collections of methods and attributes from Office.
An existent PDF is not the case (Access can create one or open, but not open and print).
To open a file with full path you will need to perform a select from table and perform a loop to shell open file, after that, sendkeys ^P.
But I strongly recomend to use another tool to do it, like Auto Hotkey or AutoIt.
In Visual Basic 2010 Express, I use SQL statements to read, write, edit, ... a mdb database file. However, at the moment, it's pointing to a location on my local directory.
Is there a way to embed the file into the VB program and change the SQL statement to write to it?
Sort of like how in HTML, you can move the whole website folder and so long, as the root contains the folder "images" for example, then it knows to look in there...
I don't know how you are currently stating the connection string for each of your sql statements, but one approach that you could take would be to place the .mdb file in the root folder of your application and then use the generic
Application.Info.DirectoryPath
to provide the basic location of the mdb file. A better idea however (especially to avoid problems with with the UAC and permissions would be to place the mdb file in the all users application data folder and use the equally generic pointer
Application.CommonAppDataPath
With some judicious experimentation you should be able to arrive at a solution that best meets with your own requirements.
Your reference to your MDB file will likely be contained in your app.config file as an SQL connection string. In there you'll find the full path to the file itself. If you change that to a relative path (say, just the name of the MDB file itself, no folders or anything like that) then it should look in the directory of the executable.
So, if your connection string was:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyFolder1\mydatabase.mdb;User Id=admin;Password=;
You'd change it to:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=mydatabase.mdb;User Id=admin;Password=;
No you can't use an Access database as embedded as a resource.
You could set the connection string like this
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|\myDatabaseFile.mdb;Persist Security Info=False;
and then in your startup code you could set the substitution for the DataDirectory with a call to
Dim commonAppData = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
AppDomain.CurrentDomain.SetData("DataDirectory", commonAppData)
Lacking this call then your DataDirectory predefined value will be the current application startup folder.
Some info on |DataDirectory| sustitution string
I am making a small application that will read .csv files into a newly generated access table (generated with vb.net), I am filling this database with sql and now I would like to output that table as a .dbf file!
I can't find any info on this subject.
I know some of you will tell me to just make the script in vba in access, but there are some functions that require me to use vb.net and the client wants a single .exe file.
There is a forum post here that includes some VB.NET sample code to create a .dbf file and write some data into it. The code uses the Visual FoxPro OLEDB driver (VFPOLEDB) which is no longer distributed with Windows by default, but can be downloaded here.
I have a stand-alone Windows Form app written in VB.NET that currently connects to a local Access DB (.mdb file) and consumes data from several of the tables. It never writes to nor modifies the DB. I'm trying to figure out how to secure this DB so the user has no access to it. I'm thinking the best way is to store the DB as an embedded resource within the project. However, I can't figure out how to make this work.
I've added the .mdb file to the project resources and set its properties to "Embedded Resource" and "Do not copy." But now how do I reference the DB to create the connection?
Before I used the connection string "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=MyDatabase.mdb"
How do I write the connection string now with reference to an embedded resource?
"I'm thinking the best way is to store the DB as an embedded resource within the project."
This usually relates to old skool security, in the olden days DotNetNuke developers that used Access dBs as their backend actually renamed the .mdb to .resources as you cant download a resource file from the web.
"Would it be better to export the DB to xml or something like that and then use a stream reader as opposed to a database connection?"
No. You cant read an Access file from a stream And an XML dB has even less concurrency support than an Access Database.
If you really need to protect the data, then you've absolutely chosen the wrong data store.
#JohnBustos wrote "Store the DB remotely and have the program access it over the internet."
Please do not do this. If anything put it on a network share and restrict access. Then look at upgrading the access dB to SQL Server.
Yes, I have had the same problem and I converted the database into a XML or even a TXT file that is embedded. It works very fine !
Sorry, I never closed this out.
My solution was even simpler than those proposed. You can add the .mdb file to the project itself and not mess with the whole "Resource" business. Then set the file's Copy to Output property to "Do not copy". So the .mdb gets compiled into the app, but file itself is not available to the user.