c# - Import excel to SharePoint 2010 custom forms -
c# - Import excel to SharePoint 2010 custom forms -
i having problem in uploading excel info .net forms deployed on sharepoint 2010 environment. functionality upload excel trough .net forms , excel saved location on server. 1 time excel saved on server microsoft.ace.oledb.12.0 provider fetch info excel , upload comma separated values on .net text box control.
here challenges facing currently.
1.) functionality working when user logged in service account(higher permissions account) on sharepoint 2010. 2.) tried logging in user business relationship on sharepoint did not work , throwing error below. think happening due permissions issue. cannot assign users service business relationship permissions.
is there way can impersonate login service business relationship finish activity of uploading excel , dispose login of user account? or suggestions help me prepare issue?
error message:
error occured: system.data.oledb.oledbexception: unspecified error @ system.data.oledb.oledbconnectioninternal..ctor(oledbconnectionstring constr, oledbconnection connection) @ system.data.oledb.oledbconnectionfactory.createconnection(dbconnectionoptions options, object poolgroupproviderinfo, dbconnectionpool pool, dbconnection owningobject) @ system.data.providerbase.dbconnectionfactory.createnonpooledconnection(dbconnection owningconnection, dbconnectionpoolgroup poolgroup) @ system.data.providerbase.dbconnectionfactory.getconnection(dbconnection owningconnection) @ system.data.providerbase.dbconnectionclosed.openconnection(dbconnection outerconnection, dbconnectionfactory connectionfactory) @ system.data.oledb.oledbconnection.open() @ system.data.common.dbdataadapter.quietopen(idbconnection connection, connectionstate& originalstate) @ system.data.common.dbdataadapter.fillinternal(dataset dataset, datatable[] datatables, int32 startrecord, int32 maxrecords, string srctable, idbcommand command, commandbehavior behavior) @ system.data.common.dbdataadapter.fill(dataset dataset, int32 startrecord, int32 maxrecords, string srctable, idbcommand command, commandbehavior behavior) @ system.data.common.dbdataadapter.fill(dataset dataset) @ segmentationtool.createsegment.btnfileuploadfordnis_click(object sender, eventargs e)
code:
strtarget = fileuploadfordnis.filename; string[] arrcheckextension = strtarget.split('.'); if (arrcheckextension.length >= 2) { if (arrcheckextension[1].tostring().equals("xls") || arrcheckextension[1].tostring().equals("xlsx")) { fileuploadfordnis.saveas("b:\\test\\" + strtarget); strconnforexcel = string.format(@"provider=microsoft.ace.oledb.12.0;data source={0};extended properties=""excel 12.0;hdr=yes;imex=1;""", "b:\\test\\"+strtarget); strqueryforexcel = string.format("select dnis_id [{0}$]", "oms_dnis"); oledbdataadapter adapfordnis = new oledbdataadapter(strqueryforexcel, strconnforexcel); dsfordnis = new dataset(); adapfordnis.fill(dsfordnis); if (dsfordnis.tables[0].rows.count > 0) { (int = 0; < dsfordnis.tables[0].rows.count; i++) { if (strdnisids == "") { strdnisids += dsfordnis.tables[0].rows[i]["dnis_id"].tostring(); } else { strdnisids += "," + dsfordnis.tables[0].rows[i]["dnis_id"].tostring(); } } txtspecacquwinbackdnisforupload.text = strdnisids; rdomscspecificvalue.focus(); system.io.file.delete("b:\\test\\" + strtarget); } } else { response.write("<script language='javascript'>alert('please select file .xls or xlsx extension');</script>"); fileuploadfordnis.focus(); } }
the system account user specified iis application pool, suppose user have permission write b:\test folder, other user not have permission , reason operation fail.
you can utilize runwithelevatedpermission , code run under scheme business relationship privilege.
however suggest you:
1) utilize microsoft openxml read/write office files, improve utilize wrapper library simplify operations exceldatareader or closedxml
2) can save file document library instead of file scheme (if have multiple frontend file scheme not improve solution..)
3) code see you not need save excel, can process excel file in memory (stream) see point 1
hope help.
c# asp.net .net sharepoint-2010 impersonation
Comments
Post a Comment