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.....
Microsoft SQL ServerMicrosoft SharePointMicrosoft Server Apps

Avatar of undefined
Last Comment
BKennedy2008

8/22/2022 - Mon
Rainer Jeschor

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
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
DcpKing

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
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
BKennedy2008

ASKER
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.
Rainer Jeschor

hi,
good starting point is here
http://msdn.microsoft.com/en-us/library/gg749858.aspx

Hth,
Rainer
BKennedy2008

ASKER
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
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
BKennedy2008

ASKER
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
Rainer Jeschor

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
BKennedy2008

ASKER
Yes, that was a mistake, but I set it to ItemsAdded instead of ItemsAdding, and no luck...
BKennedy2008

ASKER
Actually, the code above works fine when I set it to itemsadded....
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes