Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 15th, 2007, 02:56 PM
Registered User
 
Join Date: Oct 2007
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

    rs.Edit


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

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

    Set rs2 = Nothing
 
Old October 16th, 2007, 06:46 AM
Friend of Wrox
 
Join Date: Mar 2004
Posts: 3,069
Thanks: 0
Thanked 10 Times in 10 Posts
Default

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?

mmcdonal
 
Old October 16th, 2007, 07:24 AM
Registered User
 
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
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.
try
{
// 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.

Eliza
__________________
Cheers,
Eliza

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





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





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