Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 15th, 2007, 02:56 PM
Registered User
Join Date: Oct 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default adding attachments to sharepoint list via code

I have a table created in access 2007. I basically have 3 fields.

ID - (pk)
Job - (number)
NewDoc - (Attachment)

I have some code that used the .LoadFromFile and it worked great. So i could scan a document in and then load that scan document into the database. So to prevent the database size from growing outrageously, I moved that table to our sharepoint server using the export to sharepoint list command on the ribbon.

I can go into the list and double click on the attachment to add a new attachment to any record. However, I cannot use the .LoadFromFile function any longer. I get an invalid argument from this.

The server is running MSS 3.0 using SQL Express as the backend. I am making an assumption by thinking that if i can double click on attachment area in the sharepoint list to add a document then I should be able to do this via code.

Here is a small portion of the code below.

Const strTable = "tbldocs"

    Dim rs As DAO.Recordset
    Dim dbs As DAO.Database
    Dim rs2 As DAO.Recordset2

    Set dbs = CurrentDb
    Set rs = Me.Recordset


    Set rs2 = rs.Fields("Attachments").Value

    rs2.Fields("FileData").LoadFromFile ("c:\image\test.pdf")

    Set rs2 = Nothing
Reply With Quote
  #2 (permalink)  
Old October 16th, 2007, 06:46 AM
Friend of Wrox
Points: 9,611, Level: 42
Points: 9,611, Level: 42 Points: 9,611, Level: 42 Points: 9,611, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Mar 2004
Location: Washington, DC, USA.
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts

The first thing that jumps out is that you are using DAO for SQL, which only works for Jet. ADO is needed here.

Secondly, Microsoft does not support manipulating SharePoint content tables, except through the SharePoint aspx interface.

Anyway, I bet it is the ADO. Alternatively, even if you paste the file as an attachment using your code, the aspx application may not recognize that one is there unless you modify the <ListViewXml></ListViewXml> tags on the List's aspx page to show the attached file icon and other data to show the page how to get the file.

Lastly, what is the maximum file size for SQL Express? As you attach files, this list could shut down Express if there is a limit. I thought there might not be a limit with this newest version of MSDE.

Did any of that help?

Reply With Quote
  #3 (permalink)  
Old October 16th, 2007, 07:24 AM
Registered User
Join Date: Oct 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts

I believe it's the actual field type in sql express that is causing the problem. I can use the DAO connection to add any text to the table in any row. However, it just doesn't work for the attachment field.

Keep in mind I'm linking these lists into access 07. I have a sql server coming this week so I am going to reload sharepoint onto that with a SQL backend instead of the sql express. I'm thinking it should work alot better.
Reply With Quote
  #4 (permalink)  
Old June 18th, 2010, 03:40 AM
Authorized User
Join Date: Jan 2010
Posts: 22
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to elizas
Default Adding an Attachment to a List Item Programmatically in SharePoint

Below is code snippet in c#.net for fetching all the attachements for a specific list item.
// Set the Site Url
SPSite objSite = new SPSite("http://Testsite/");

using (SPWeb objWeb = objSite.OpenWeb())
objWeb.AllowUnsafeUpdates = true;

// Get the List
SPList objList = objWeb.Lists["MyList"];

// Get the item by ID
SPListItem objItem = objList.GetItemById(1);

// Get the attachments of the item
SPAttachmentCollection objAttchments = objItem.Attachments;

// Iterate the attachments
foreach (string fileName in objItem.Attachments)
// Perform action on the extracted attachment

objWeb.AllowUnsafeUpdates = false;

Hope it did answer the question.Any suggestions are appreciated.


Mindfire: India's Only Company to be both Apple Premier & Microsoft Gold certified.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtered Sharepoint list, not filtered in infopath wmrdude SharePoint Development 0 July 26th, 2006 05:09 AM
Adding List Item Programmatically rit01 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 February 12th, 2006 04:51 PM
Use dot net code to open outlook for attachments imsuneeta General .NET 1 August 9th, 2005 07:12 AM
Help Help - Code Behind in Sharepoint? anupkumars .NET Web Services 0 June 20th, 2005 05:25 AM

All times are GMT -4. The time now is 08:43 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.