Link to home
Start Free TrialLog in
Avatar of BKennedy2008
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

Hi,
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.

HTH
Rainer
Avatar of BKennedy2008
BKennedy2008

ASKER

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 VB.net 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...

Thanks
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.

Mike
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.
hi,
good starting point is here
http://msdn.microsoft.com/en-us/library/gg749858.aspx

Hth,
Rainer
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)
            MyBase.ItemAdded(properties)
      End Sub

      ''' <summary>
      ''' An item was updated.
      ''' </summary>
      Public Overrides Sub ItemUpdated(properties as SPItemEventProperties)
            MyBase.ItemUpdated(properties)
      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();
            strWFBuilderCheck.Append(@"C:\TestFolder\");
            strWFBuilderCheck.Append(DateTime.Now.Date.Year.ToString());
            strWFBuilderCheck.Append(DateTime.Now.Date.Month.ToString());
            strWFBuilderCheck.Append(DateTime.Now.Date.Day.ToString());
            strWFBuilderCheck.Append("_");
            strWFBuilderCheck.Append(DateTime.Now.TimeOfDay.Hours.ToString());
            strWFBuilderCheck.Append(DateTime.Now.TimeOfDay.Minutes.ToString());
            strWFBuilderCheck.Append(DateTime.Now.TimeOfDay.Seconds.ToString());
            strWFBuilderCheck.Append("_");
            strWFBuilderCheck.Append(properties.ListItem.File.Name);

            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);


            binWritercheck.Write(itembytescheck);


            binWritercheck.Close();
        }



    }
}
ASKER CERTIFIED SOLUTION
Avatar of Rainer Jeschor
Rainer Jeschor
Flag of Germany image

Link to home
membership
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....