How to read excel file in document library and store excel content in sql table

Hello,
Can anyone help me how to read the excel file present in document library and store the content inside excel into sql table?
Please let me know the ways to acheive this. Feel free to give your suggestions.
Thanks,
Cool Developer

Hi!
this code i have written becuase i donot find any soltions on net for this , u can try with this . :)
System.Data.OleDb.
OleDbConnection ExcelConnection = null;
FileMode fileMode;
string filePath = ConfigurationManager.AppSettings["TempLoaction"] + "\\" + fileName;
using (SPSite _site = new SPSite(SPContext.Current.Web.Url))
using (SPWeb _web = _site.OpenWeb())
string docLibrary = ConfigurationManager.AppSettings["DocumentLibrary"];
SPFile _file = _web.GetFile("/" + docLibrary + "/" + fileName);
fileMode =
FileMode.Create;
byte[] byteArray = _file.OpenBinary();
MemoryStream dataStream = new MemoryStream(byteArray);
Stream stream = dataStream;
using (FileStream fs = File.Open(filePath, fileMode))
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = stream.Read(buffer, 0, buffer.Length)) != 0)
fs.Write(buffer, 0, bytesRead);
fs.Close();
//Create the Connection String
try
string ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;
Data Source ='"
+ filePath + "'; Extended Properties=Excel 5.0";
//Create the connection
ExcelConnection =
new System.Data.OleDb.OleDbConnection(ConnectionString);
//create a string for the query
string ExcelQuery;
//Sheet1 is the sheet name
//create the query:
//read columns from the Excel file
ExcelQuery =
"Select * from [Sheet1$]"; // from Sheet1";
//use "Select * ... " to select the entire sheet
//create the command
System.Data.OleDb.
OleDbCommand ExcelCommand = new System.Data.OleDb.OleDbCommand(ExcelQuery, ExcelConnection);
//Open the connection
ExcelConnection.Open();
//Create a reader
System.Data.OleDb.
OleDbDataReader ExcelReader;
ExcelReader = ExcelCommand.ExecuteReader();
//For each row after the first
while (ExcelReader.Read())
thanks,
kshitij

Similar Messages

  • Create excel file in document library from the data in datatable

    Hi ,
    I want to generate files dynamically and have then saved to my documetn library instead of  some location on the  harddisk.
    I want to generate and excel file  which will read data from the sharepoint list.
    Form that data excel will be genereated in the code ,and i want the generated excel directly available in the  document library.
    I could use open xml of excel itneroperablity for the excel file generation.
    How can i do that.

    Hi,
    According to your description, you might want to gather data from a SharePoint list as an excel file and upload it to a Document Library.
    As you said, you can generate an Excel file using the Open XML SDK, I will provide some information about how to get data from SharePoint list and how to upload files
    to a Document Library.
    About the retrieving data from a SharePoint list, we can use SharePoint Object Model:
    SharePoint Object Model -
    SPListItem class
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splistitem.aspx 
    Add, Update and Delete List Items Programmatically in SharePoint
    http://www.mindfiresolutions.com/Add-Update-and-Delete-List-Items-Programmatically-in-Sharepoint-372.php 
    About
    How to: Upload a File to a SharePoint Site from a Local Folder:
    https://msdn.microsoft.com/en-us/library/office/ms454491(v=office.14).aspx
    Thanks
    Patrick Liang
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support,
    contact [email protected]
    Patrick Liang
    TechNet Community Support

  • How to fast attach files from document library to e-mail?

    Hi
    I have SP2013 , and i love it to drag and drop the documents into Document library,
    it is posible that i can drag and drop the files from SharePoint document library to new E-Mail or Internet Explorer?
    tanxs for answer.

    Harmon.IE provide an outlook plug-in that provides drag-drop functionality for SharePoint within outlook and could be worth taking a look at.
    I believe it's license free up to 100 seats, but you'll need to verify that.
    Paul.
    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

  • How to read a file which has header and without header

    Hi,
    I have a file to file scenario wherein there are txt files in the source system, some of which has header and some without header.
    How does the sender adapter dynamically identify a file with header and without header.
    I knew that File content Conversion in the sender adapter with "Recordsets per message = 1" can read the header.  But how to handle dynamically.
    Thanks in advance for suggestions and advice.
    Regards.
    Praveen

    Hi,
    Let me give a more clear picture:-
    One of my file which has header and the corresponding values is listed hereunder:
    PERNR;KID;PNALT;NACHN;NAME2;VORNA;TITEL;TITL2 and so on.....
    ;1200;1200;Angus;; and so on.........
    Other file which has no header but only values in it:-
    1200;1200;;Werner;Angus and so on.......
    The structure remains same for all the files.  The only difference is that some of the file has header in it and some without header.  The Message Type is mentioned hereunder:-
    DT_LegacyEmployee (Category - Complex Type)
         Employees (Category - Element, Occurence - 1)
              Employee (Categroy - Element, Type - DT_LegacyEmployee_Row, Occurence - 0...unbounded)
                   PERNR
                   KID
                   PNALT
                   NACHN
                   NAME2 and so on......     
    I read the file in record row.  The file conversion parameters in the file sender adapter are mentioned hereunder:-
    Document Name - MT_LegacyEmployee
    Document Namespace - http://abc.com/xi
    Recordset Name - Employees
    Rescordset Structure - Employee,*
    Recordsets per Message - 1
    Key Field Type - String (Case Sensitive)
    Employee.fieldSeparator - ;
    Employee.endSeparator - 'nl'
    Employee.fieldNames - PERNR,KID,PNALT,NACHN,NAME2,VORNA,TITEL,TITL2 and so on........
    How do we dynamically identify whether the file has header or not.  Even if the file has header or without header, the file needs to be picked and transferred to the target system.  Kindly clarify.
    Regards.
    Praveen

  • How to open and read many files from a directory and store contents in 2D array?

    I want to make a VI that opens and reads the data from various files contained in a directory (200 files each with 2 columns) and store these in a single 2D array. For file number 1 I want to store the data from both columns in the 2D array, but for files 2 to 200 I only want to store the second column of each file. Can someone please help?

    Hi Nadav,
    Thanks for your help. I have followed your instructions but i cannot get it to work. I used the LIST DIRECTORY to list the files in the directory - that works. However, how do I read each of the 200 files using READ FROM SPREADSHEET FILE without me having to manually select each of the 200 files? So, if I use LIST DIRECTORY to list all 200 files in an array, how do I get each of these to open and store the data in a 2D array? Here is what I have done (File called read_files.VI) Could you please help me? Thank you very much in advance.
    Attachments:
    read_files.vi ‏18 KB

  • Cannot open Excel files on Windows share and ONLY Excel files

    I'm browsing a Windows share and for whatever reason it will not let me open Excel files directly from the network location. If I view the Coverflow, I can see a a preview of the actual file as well as copy it to the desktop and open it.
    I receive an error message that says "filename.xls could not be found."
    I can open up any other file from the network location, but not Excel files.
    I checked the file permissions and they mirror the other file types, it may be worth mentioning that I utilize network synchronization and view these files from a PC as well. I also noticed when I create a new file in that location, it will only appear in OS X and not Windows, but is still completely accessible.
    Any help is appreciated!
    Thanks

    Re:  Windows 8 vs. Excel problem
    Does your new Dell computer have MS Office installed?
    Jim Cone
    Portland, Oregon USA
    https://jumpshare.com/b/O5FC6LaBQ6U3UPXjOmX2

  • How to read a file with both text and binary data?

    For text data I use a BufferedReader,
    for binary data I use a DataInputStream.
    Since readLine is deprecated in DataInputStream, how can I read in a proper way a file that contains some lines of text followed by some binary data.
    Is there a way to do this without writing a new 'readLine' for DataInputStream (that has to take into account the different newlines for Unix en other OS's)?

    sorry about that ^
    NEW STRING str
    WHILE there is stuff in the file DO
        getByte()
        IF reading a string THEN
            WHILE byte is not a return character DO
                convert the byte to character/string
                append char to str
            WEND
        ELSE IF reading raw data THEN
            parse raw data
            do stuff with it
        END IF
    WEND

  • How to get the value from a label and store it in an sql database?

    I have tried all kinds of different ways and I always get the error that it is not a member of string or whatever data type I try.
    Try
    scoringlbl.Text.Validate()
    scoreinglbl.Text.HighScoresBindingSource.EndEdit()
    scoringlbl.Text.HighScoresTableAdapter.Update(Me.ScoresDataSet.HighScores)
    MsgBox("Update successful")
    Catch ex As Exception
    MsgBox("Update failed")
    End Try

    I know nothing about data binding, but maybe this works, or at least point you in the right direction:
    Try
    scoringlbl.Validate()
    HighScoresBindingSource.EndEdit()
    HighScoresTableAdapter.Update(ScoresDataSet.HighScores)
    MsgBox("Update successful")
    Catch ex As Exception
    MsgBox("Update failed")
    End Try
    Armin

  • Error while editing file from document library

    Dear All,
               I have some users in one of the SharePoint site with contribution access . When they try to open and edit the excel document they are facing error as below.Can any one help me how can I over come from this issue
    Thanks,
    Quality Communication Provides
    Quality Work.

    Hi siddiaqli,
    When the user edit the excel file, whether other users also edit it.
    Please try to enable Check-out/Check-in in the library, then test again, compare the result.
    You can enable Check Out/In as Library settings->Versioning settings->Require Check out.
    In addition, please create a new excel file in the library, and test again, compare the result.
    Please create a new library, and create a new excel file in the new library, test again, compare the result.
    Thanks,
    Wendy
    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact
    [email protected]

  • What are the commands available to read a file from application server and

    What are the commands available to read a file from application server and store the file into an internal table?

    Hi,
    To read a file from an Application Server to an Object there is a command in ABAP called <b>READ DATASET</b>. After that file is transported to that object you have to do a loop and put that data in an Internal Table.
    This statement exports data from the file specified in dset into the data object dobj. For dobj, variables with elementary data types and flat structures can be specified. In Unicode programs, dobj must be character-type if the file was opened as a text file.
    For dset, a character-type data object is expected - that is, an object that contains the platform-specific name of the file. The content is read from the file starting from the current file pointer. After the data transfer, the file pointer is positioned after the section that was read. Using the MAXIMUM LENGTH addition, the number of characters or bytes to be read from the file can be limited. Using ACTUAL LENGTH, the number of characters or bytes actually used can be determined.
    In a Unicode program, the file must be opened with an arbitrary access type; otherwise, an exception that cannot be handled will be triggered.
    If the file has not yet been opened in anon-Unicode program, it will be implicitly opened as a binary file for read access using the statement
    OPEN DATASET dset FOR INPUT IN BINARY MODE.
    . If a non-existing file is accessed, an exception that can be handled can be triggered.
    Influence of Access Type
    Files can be read independently of the access type. Whether data can be read or not depends solely on the position of the file pointer. If the latter is at the end of the file or after the file, no data can be read and sy-subrc will be set to 4.
    Influence of the Storage Type
    The import function will take place irrespective of the storage type in which the file was opened with the statement OPEN DATASET.
    If the file was opened as a text file or as a legacy text file, the data is normally read from the current position of the file pointer to the next end-of-line marking, and the file pointer is positioned after the end-of-line marking. If the data object dobj is too short for the number of read characters, the superfluous characters and bytes are cut off. If it is longer, it will be filled with blanks to the right.
    If the file was opened as a binary file or as a legacy-binary file, as much data is read that fits into the data object dobj. If the data object dobj is longer than the number of exported characters, it is filled with hexadecimal 0 on the right.
    If the specified storage type makes conversion necessary, this is executed before the assignment to the data object dobj. Afterwards, the read data is placed, byte by byte, into the data object.
    System Fields
    sy-subrc Meaning
    0 Data was read without reaching end of file.
    4 Data was read and the end of the file was reached or there was an attempt to read after the end of the file.
    Thanks,
    Samantak.
    <b>Rewards points for useful answers.</b>

  • How to add a record in document library without upload file.

    Hi,
    how to add a record in document library without upload file?
    Is it possible? I want to create a folders in Document Library but inside folders i do not want to upload a file instead of just i want to create a record. I will map my local file path to the records.
    Can anyone help me on it?
    Thanks & Regards
    Poomani Sankaran

    Hello Sankaran,
    document library is to upload documents, without document you will not be able to add a record or Item to it.
    for your requirement you can use a list and enable folders within the list and maintain the local path of the file as an item in list.
    http://www.sharepointbriefing.com/spconfig/article.php/3834951/Enable-the-New-Folder-Creation-Option-in-SharePoint-Custom-Lists.htm
    My Blog- http://www.sharepoint-journey.com|
    If a post answers your question, please click Mark As Answer on that post and Vote as Helpful

  • How to update managed metadata column for all file in document library using powershell

    Hi,
    How to update managed metadata column for all file in document library using powershell?
    Any help on it.
    Thanks & REgards
    Poomani Sankaran

    Hi TanPart,
    I have changed the code which you have give in order to get the files from SharePoint 2010 Foundation  Document Library.But i am getting below error in powershell.
    Property 'ListItemCollectionPosition' cannot be found on this object; make sure it exists and is settable.
    Could you tell me which is the issues in it?
    See the code below.
    $web = Get-SPWeb http://ntmoss2010:9090/Site
    $list = $web.Lists["DocLib"]
    $query = New-Object Microsoft.SharePoint.SPQuery
    $query.ViewAttributes = "Scope='Recursive'";
    $query.RowLimit = 2000
    $caml = '<Where><Contains><FieldRef Name="Title" /><Value Type="Text">Process Documents/Delivery</Value></Contains></Where>' +
            '<OrderBy Override="TRUE"><FieldRef Name="ID"/></OrderBy>'
    $query.Query = $caml
    do
        $listItems = $list.GetItems($query)
        $spQuery.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
        foreach($item in $listItems)
            #Cast to SPListItem to avoid ambiguous overload error
            $spItem = [Microsoft.SharePoint.SPListItem]$item;
            Write-Host $spItem.Title       
    while ($spQuery.ListItemCollectionPosition -ne $null)
    Thanks & Regards
    Poomani Sankaran

  • How external users can upload files in document library hosted in onpremise SharePoint?

    Hi all,
    We have setup a document library(DL) in SharePoint site hosed on-premise with no direct access from public zone/internet being an intranet solution. We have some external users who need to upload some files that needs to go in this document
    library. These files are quite confidential in nature so security is a prime requirement. Following are the couple of options I have in mind:
    1. External users upload their file in their designated folder to secure FTP using their own credential set. And also there is a background process (kind of directory watcher) that keep looking at the all the folders
    and moves the files to document library
    2. We host a single page application which has One time password (OTP) kind of feature. External user comes to the secure site to specify Vendor team name and mobile number. OTP is generated and user is asked to specify the password along with file
    they would like to upload. This page also maps the vendor name with respective folder in DL and moves the files to SharePoint there on the fly.
    Pls. share your opinion about these approaches. Also welcome your thoughts if there is any other better option.
    Thanks.

    Hi,
    I agree with the Margriet, the first option is simple and safe, the users could not access the document library directly.
    For security, it is an importance for users not access the document library directly, it will reduce the risk of the documents in the library.
    Thanks,
    Jason
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Jason Guo
    TechNet Community Support

  • How do document permissions differ from its document library and a content roll-up webpart?

    I have an excel spreadsheet (a group schedule), in a document folder, on a page that only IT management can see/access/edit, in a site that all IT group members have access to.
         for example: http://IT Group site/IT Management Page/Schedule/2015.xlsx
    On the group's homepage, I have a content roll-up web part that displays all document library contents in the group site.
    IT management consists of 3 people. They can all edit the spreadsheet from the original location, but when they access the document from the content roll-up web part on the group's homepage, they cannot save any changes.
         Accessing the file from here: http://IT Group site - content roll-up web part link "2015.xlsx" points to "IT Group site/IT Management Page/Schedule/2015.xlsx"
    The error received says "'http://IT Group site/IT Management Page/Schedule/2015.xlsx' is read-only. To save a copy, click OK, then give the workbook a new name in the Save As dialog box."
    Where would the permission issue be?
    As the SharePoint site owner, I can access the file without any problems saving from either location. Also, I created an IT Management group that has full control over the IT Group site/IT Management Page, and full control over the IT Group site.
    Thanks for any info you can share.
    Stephanie

    Thanks Cameron -
    I have no special settings on the document library where the schedule is saved. No content approval necessary or different permissions. The library is set to open documents in client application, and check-in, check out is not activated.
    I have logged in to one of their computers. They can access the spreadsheet directly from the document library and make changes freely, and save that version directly to the server, but not from any web parts. Just to test, I created a summary link web part
    on the same page that lists the document library, created a link to the file, and the file opens, but they cannot save any changes without renaming the file. The only place they can truly edit the spreadsheet without renaming is from the document library
    directly.

  • Schedule the Publishing date of a file in Document Library using CSOM

    I am having a hard time to schedule the publishing date of a document uploaded to a sharepoint document library. Basicaly, what I want is to upload a file to a document library and to schedule it´s publishing for a future date, using CSOM. Then someone should
    approve this (file content and scheduled date and time for publishing).
    I am able to upload the document to the document library and to start the approval workflow automatically (when the document is uploaded), but I don´t know how to set the publishing date using client side object model.
    Apparently all I need to do is to set up the properties ScheduledItem.StartDate and ScheduledItem.EndDate, but I just can´t manage to do it. Any help will be very much appreciated.

    I am having a hard time to schedule the publishing date of a document uploaded to a sharepoint document library. Basicaly, what I want is to upload a file to a document library and to schedule it´s publishing for a future date, using CSOM. Then someone should
    approve this (file content and scheduled date and time for publishing).
    Scheduling is enable and the coluns StartDate and EndDate are already added to the document library. I am able to upload the document to the document library and to start the approval workflow automatically (when the document is uploaded), but I don´t know
    how to set the publishing date using client side object model.
    Apparently all I need to do is to set up the properties ScheduledItem.StartDate and ScheduledItem.EndDate, but I just can´t manage to do it. Any help will be very much appreciated.

Maybe you are looking for

  • BO Universe Objects

    Hi all I want a list of all the objects in my universe, with the foll details : Class Name, Description, Object Name, Object Description,SQLCode(definition). Is there a query I can use to query the system tables to get this information. Please help!

  • Adobe AIR installation and testing

    Hi, Can anyone say why Adobe AIR does not function correctly in my PC (Vista Home Premium). When I try to run a test application after installation through AIR SDK command-line tool (adl AIRHelloWorld.xml), console window opens but shuts down immedia

  • SCN Editor capitalization bug on iPad

    Hi All, I am constantly using iPad to post answers in SCN forums when I am traveling. It's fine to read discussions using Safari browser but when I post the answer I have very annoying bug with capitalization: not only the first letter is capitalized

  • Searching for Data Modell

    Hello, I need some further information about the data modell of SBO. An ERD would be great, but as far as I know there is no such diagram available. Searching in this forum gave me the information that that there are two useful files: - SBOObjectsTab

  • How can i upload hq photos from my iphone

    whenever i post photos directly from camera roll it compresses.. i just hate it