Link to home
Start Free TrialLog in
Avatar of BKennedy2008

asked on

file upload to SharePoint Copy to a folder......

Can someone point or navigate me in SharePoint 2010 towards this task:
(I am assuming this is going to be a Workflow setting that is not Out of the Box...)

If a file is uploaded to a SharePoint 2010 document library, I need it to make a copy of the file into a folder on the Server...........not in SharePoint, but a folder that resides on the Server.

Sounds Easy, but with my Luck, it's probably not.....
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

I think you have to program either an event receiver to do this job or a custom coded workflow.

Perhaps an alternativ is to program a tool using FileSystemWatcher and bind that to a UNC mapped SharePoint document library.

Avatar of BKennedy2008


I wnet down the road for  FileSystemWatcher task, and it is not going to work. I have to move the file out of the system watch folder (SharePoint Document Library) which in my situation is not going to work for me.

I may have a 100 folders with 30 files in each, and I cannot be moving files out of the watched folder as they get copied to another folder.

I am leaning towards the event receiver. I know alot about code, but I have never have programmed in SharePoint. I think that is what I need to do, but I need to get steered in the right direction to do this. I am hoping to figure it out in hours and not days...

Did you check my last comment in your other thread? Instead of just watching for files, watch for files that are newer than the last one your process copied.

Yes, I did. As i thought about it, I think a more stable solution would be to program an event receiver to copy a file to the destination folder as it is created, updated, and deleted as in the case of the files contained in a Sharepoint Site are doing.
good starting point is here

Thanks Rainer, I have installed VS2010 on the SharePoint Server and created a new event receiver for files in a document library that look for a new file or an updated file, but looking where to go from here...Thanks

Option Explicit On
Option Strict On

Imports System
Imports System.Security.Permissions
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Security
Imports Microsoft.SharePoint.Utilities
Imports Microsoft.SharePoint.Workflow

Public Class EventReceiver1
    Inherits SPItemEventReceiver

      ''' <summary>
      ''' An item was added.
      ''' </summary>
      Public Overrides Sub ItemAdded(properties as SPItemEventProperties)
      End Sub

      ''' <summary>
      ''' An item was updated.
      ''' </summary>
      Public Overrides Sub ItemUpdated(properties as SPItemEventProperties)
      End Sub

End Class
The following code is supposed to copy a file to a local folder once it is uploaded in SharePoint library, but its not working........

using System;
using System.IO;
using System.Text;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;

namespace EventReceiverProject2.EventReceiver1
    /// <summary>
    /// List Item Events
    /// </summary>
    public class EventReceiver1 : SPItemEventReceiver
       /// <summary>
       /// An item is being added.
       /// </summary>
       public override void ItemAdding(SPItemEventProperties properties)
            StringBuilder strWFBuilderCheck = new StringBuilder();

            string WorkfFileLocationcheck;
            WorkfFileLocationcheck = strWFBuilderCheck.ToString();

            BinaryWriter binWritercheck = new BinaryWriter(File.Open(WorkfFileLocationcheck, FileMode.Create));
            byte[] itembytescheck = properties.ListItem.File.OpenBinary();
            string itemstringcheck = Encoding.ASCII.GetString(itembytescheck);
            System.Text.ASCIIEncoding encodingcheck = new System.Text.ASCIIEncoding();
            byte[] bytescheck = encodingcheck.GetBytes(itemstringcheck);



Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, that was a mistake, but I set it to ItemsAdded instead of ItemsAdding, and no luck...
Actually, the code above works fine when I set it to itemsadded....