sql - Document Upload to SharePoint with VB.NET -


at company have initiative allows users submit "winning ideas". there form fill out, , user can upload documents on form. ideas voted on other employees, reviewed committee, , user has ability win cash prizes , have idea implemented in company.

i created custom webpart using asp.net allows users insert row sql table, , add documents sharepoint document list. list of documents upload added field in sql table, , displayed hyperlinks on .aspx page.

here of issues have seen document upload:
- document not uploaded @ all.
- document uploaded, not checked in.
- document uploaded , checked in, not linked record (the field did not update in sql).
- if adding multiple documents, both documents uploaded content of first document repeated documents.
- multiple entries created insert statement.

i can't figure out if problem sql or vb. there better way should doing this? appreciated.

my current environment such:
- sharepoint 2013
- sql server 2012
- microsoft visual studio professional 2013

partial public class winningideasformusercontrol inherits usercontrol public conn sqlconnection public strdatabase string public myuserinfo spuser public strfiles string public ideaid string public uploads httpfilecollection  private sub btnsubmit_click(byval sender object, byval e system.eventargs) handles btnsubmit.click     'reference file collection sent browser request'     uploads = httpcontext.current.request.files       try         conn = new sqlconnection(strdatabase)         dim cmd sqlcommand = new sqlcommand()         strfiles = ""          'sql command insert results database'         cmd.connection = conn         cmd.commandtype = commandtype.text         cmd.commandtext = "insert [winningideas] (title, idea, submitter, spuserid) output inserted.id values (@title, @idea, @submitter, '" & myuserinfo.id & "')"          cmd.parameters.addwithvalue("@title", txttitle.text)         cmd.parameters.addwithvalue("@idea", txtidea.innertext)         cmd.parameters.addwithvalue("@submitter", myuserinfo.name)          'confirms database has been updated'         cmd.connection.open()         dim reader sqldatareader = cmd.executereader()         reader.read()         'set ideaid output of record added (id assigned in database)'         ideaid = reader(0).tostring         cmd.connection.close()         cmd.connection = nothing          if uploads.count > 1             try                 'if user uploaded documents, make sure add them'                 uploaddocuments()             catch ex exception                 span1.innerhtml = "an error has occurred while trying upload document(s). please contact winndesk@winnco.com more information. " & ex.message & "."             end try         elseif (reader.recordsaffected = 1) 'if record has been created'             sendemail()             response.redirect("/pages/submitted.aspx?ideaid=" & ideaid)         end if      catch ex exception         'change <span> show error message'         span1.innerhtml = ex.message     end try end sub  public sub uploaddocuments()     'upload files'     integer = 0 (uploads.count - 1)         dim filesize int64         filesize = uploads(i).contentlength         'get file name whichever file saving'         dim filname string = system.io.path.getfilename(uploads(i).filename)         'todo: size exception bringing user exception page. catch exception'         'make sure there no empty files, make sure file less 50mb'         if (filesize > 0 , filesize < 52428800)             dim spfile spfile = spcontext.current.web.files.add("/documents/user%20uploads/" + ideaid + "_" + filname, filefield.postedfile.inputstream)             spfile.checkin("checked in " & myuserinfo.name & " idea " & ideaid, spcheckintype.majorcheckin)             spfile.publish("published " & myuserinfo.name & " idea " & ideaid)             'separate files ";" in database'             strfiles = strfiles + ideaid + "_" + filname + ";"         else             throw new exception("your file, " & filname & ", not uploaded correctly due size.")         end if     next      try         conn = new sqlconnection(strdatabase)         dim cmd sqlcommand = new sqlcommand()          cmd.connection = conn         cmd.commandtype = commandtype.text         cmd.commandtext = "update winningideas set documents = @documents id = " & ideaid          cmd.parameters.addwithvalue("@documents", strfiles)          cmd.connection.open()         cmd.executenonquery()         cmd.connection.close()         cmd.connection = nothing          response.redirect("/pages/submitted.aspx?ideaid=" & ideaid)     catch ex exception         'change <span> show error message'         span1.innerhtml = ex.message     end try end sub 


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -