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

BKennedy2008
BKennedy2008 used Ask the Experts™
on
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.....
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2013
Awarded 2012

Commented:
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

Author

Commented:
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

Commented:
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
Success in ‘20 With a Profitable Pricing Strategy

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
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.
Most Valuable Expert 2013
Awarded 2012

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

Hth,
Rainer

Author

Commented:
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

Author

Commented:
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();
        }



    }
}
Most Valuable Expert 2013
Awarded 2012
Commented:
Hi,
I assume you should override the events
ItemAdded and ItemUpdated
and not the ...ing events.
I will try it tomorrow on my dev system.
kr
Rainer

Author

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

Author

Commented:
Actually, the code above works fine when I set it to itemsadded....

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial