Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi what i want to do is enable the user to select an excel file from the disk and then make a connection to the file.

 

I am using the HTML control file field and using it as a server control. I get the file name , add it to my connection string and try to open the connection.

 

 

string FileName = InputFile.Value;

ConnectString = @"provider=Microsoft.Jet.OLEDB.4.0;data source=+FileName;Extended Properties=Excel 8.0;";

 

OleDbConnection Connection = new OleDbConnection();

 

Connection.ConnectionString = ConnectString;

Connection.Open();

 

 

I get the following error,

"The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data."

 

If i hard code the filename in the connection string i dont get the error.

 

Any idea about this?, i am not opening the file using FileName.Value, just getting its name.

 

thanks

Sam

Posted

Thanks

 

Thanks to both of you, Robby the quotes you suggested, worked. bungpeng i am thinking about your question and i feel i have it planned the wrong way. I am fairly new to web based stuff. Yes i think now i will write code where he will upload the file to the sever first and then will call the code to open it.

Do you know which controls i should use, or do u have a asnippet ?

thanks

Sam

Posted

Hi guys thanks for the earlier replies, now i have modified my code so that i first uplaod the file to the server , and then try to open it.

I am uploading and saving it using

 

InputFile.PostedFile.SaveAs(FilePath);

 

After this i again construct my connection string using Robbys suggestion of putting quotes and when i run it i am back to square one where it gives me the error.

 

"The Microsoft Jet database engine cannot open the file ''. It is already opened exclusively by another user, or you need permission to view its data."

 

why does this not work after uploading. Also I have used saveAs so i expected to find the file uploaded at the path i specified , but i dont see the file there?

 

kind of confused? any suggestions

thanks

Sam

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...