Web Images Videos Maps News Groups Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Programmatically attach a file to a list item (c#)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
jman0  
View profile  
 More options Jul 1, 8:04 pm
Newsgroups: microsoft.public.sharepoint.portalserver
From: jman0 <jm...@zapo.net>
Date: Wed, 1 Jul 2009 03:04:50 -0700 (PDT)
Local: Wed, Jul 1 2009 8:04 pm
Subject: Programmatically attach a file to a list item (c#)
I'm developing a custom webpart to substitute the standard webpart on
the NewForm.aspx and EditForm.aspx and create and edit elements on a
list. The list must allow attaching files to list items, so I've
programmed a way to do this, but I have a problem.

If I open the site on the MOSS Server, everything runs fine and the
files get attached properly, but if I do it from any of the clients on
the network, I get "file not found" exceptions. I've tried
impersonating local accounts on the client machines and even service
accounts (i.e. "NT AUTHORITY\NETWORK SERVICE", but I always get a
"incorrect user name or password" exception.

The code which throws the exception is this:

            FileStream file = null;

            // Read the file. This appears to be the offending line
            file = File.OpenRead(Path);

            // Path is a string parameter containing the local path to
the file (i.e. c:\folder\file1.txt)

            // Store file contents in a byte array
            byte[] Content = new byte[file.Length];
            file.Read(Content, 0, (int)file.Length);
            file.Close();
            file.Dispose();

            SPAttachmentCollection AttachmentList = Item.Attachments;

            // Item is the SPListItem object I'm working with

            string FileName = GetFileName(Path);

            // GetFileName is a static method I made, to extract the
name of the file from its path

            AttachmentList.Add(FileName, Content);

How does MOSS internally accomplish such a thing? I've never had to it
set up so it impersonates local or network accounts, and MOSS always
browses the local drives and attaches the files without trouble.

Thanks in advance.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google