Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8503125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:40:25+00:00 2026-06-11T01:40:25+00:00

I am pretty much going crazy trying to get a SharePoint List Event Receiver

  • 0

I am pretty much going crazy trying to get a SharePoint List Event Receiver to work. I have created an EventReceiver Project in VS and can debug it however, the break points don’t work. Basically its the same issue lots of people have had but none of their solutions seem to work. I posted this before and I think my event receiver code should work but I can’t seem to get it working on the list itself. (my code is pasted below)

Basically all I need is for the Event Receiver to rename a document that is uploaded. Consider this scenario, if a document is uploaded called Client A Document and is the first document it should be called Client A Document 1. If the next document uploaded is called Client A Document, it should be renamed to Client A Document 2 and so on. Now if another document is uploaded, named Client B Document, it should just be Client B Document 1 since there are no others with the same name. Now I think my code below accomplishes this behaviour (code was written thanks to Robert Christs help!) but I don’t know how to test it.

Do I upload a document or create a new one? I have tried both and nothing works, anyone have any ideas how to accomplish this? I’m starting to lose my mind with this requirement.

public override void ItemAdding(SPItemEventProperties properties)
{
   base.ItemAdding(properties);

   SPListItem item = properties.ListItem;

   if (item == null || item["Name"] == null) //item["Name"] == null)
       return; //or better yet, log 

   string oldFileName = item["Name"].ToString();

   int positionOfPeriod = oldFileName.LastIndexOf(".");
   string tempFileName = oldFileName.Substring(0, positionOfPeriod);

   SPQuery query = BuildArbitraryQuery(properties.List, "Name", tempFileName, true);
   int count = properties.List.GetItems(query).Count;
   String fileName, fileExtension;

   if (positionOfPeriod == -1)
   {
       fileName = oldFileName;
       fileExtension = "";
   }
   else
   {
       fileName = oldFileName.Substring(0, positionOfPeriod);
       fileExtension = oldFileName.Substring(positionOfPeriod);
   }

   string newFileName = fileName + "-xx" + count.ToString() + fileExtension;

   item["Name"] = newFileName;

   Console.WriteLine("New File Name: " + newFileName);

   try
   {
       properties.Web.AllowUnsafeUpdates = true;
       EventFiringEnabled = false;

       item.Update();
   }
   finally
   {
       properties.Web.AllowUnsafeUpdates = false;
       EventFiringEnabled = true;
   }
}
/// <summary> 
/// Builds an arbitrary SPQuery which filters by a single column value. 
/// </summary> 
/// <param name="list">The list you will run the query against.</param> 
/// <param name="columnDisplayName">The Display Name of the column you want to filter.</param> 
/// <param name="value">The value to filter against.</param> 
/// <returns>A new SPQuery object ready to run against the list.</returns> 
public static SPQuery BuildArbitraryQuery(SPList list, string columnDocumentName, string value, bool deepSearch)
{
   if (list == null)
       throw new ArgumentNullException("You cannot pass a null list to Helper.BuildArbitraryQuery.");

   if (!list.Fields.ContainsField(columnDocumentName))
       throw new ArgumentException("The SharePoint List \"" + list.Title + "\" does not contain the Field \"" + columnDocumentName + "\".");

   string internalName = list.Fields[columnDocumentName].InternalName;
   SPQuery query = new SPQuery();
   query.Query = "<Where><Eq><FieldRef Name=\"" + internalName + "\"/><Value Type=\"Text\">" + value + "</Value></Eq></Where>";

   if (deepSearch)
       query.ViewAttributes += "Scope='RecursiveAll'";

   return query;
}

EDIT:————————————————–
Ok so I did a little test started with the same project type (event receiver) and created a very simple ItemAdded method to change the name of a list item to the current date. Now this works on a custom list but I can’t seem to get this working with a document library.

So from this little test I know that I can register an event recevier to a custom list (sandboxed solution) using F5 and debugging it, but what is different about document libraries? And is my code that I pasted not ok for what I am trying to do on a document library?

This is the code I used for the small test but it doesnt work on document libraries, even if I create a new project type for document libraries rather than custom lists (this is in ItemAdded)

       SPListItem currentItem = properties.ListItem;
       currentItem["Title"] = DateTime.Now.ToString();
       currentItem.Update();
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:40:27+00:00Added an answer on June 11, 2026 at 1:40 am

    Here is what you should do:

    1. Restart IIS “to unload the DLLs if they are used”
    2. Put your DLL and its pdb file in the GAC folder that is appropriate for this DLL
    3. open SharePoint web site such that an new w3wp process is started.
    4. Attached your VS project to the w3wp make sure you choose managed code in the attach to process dialog.
    5. Try to upload a file 6- you should be able to catch break point now.

    You can make Shell Script that can be called in post-build event to automate all this steps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hey the title pretty much says it all. i have been trying different methods
I have a custom data structure that is pretty much a list of string
I was going through number of pages in google and pretty much all answers
Pretty much the same as this question. But I can't seem to get this
Title pretty much describes it, I just need to get all the order numbers
I am creating a View that needs to consume pretty much any gesture going.
Pretty much as the question says, I have some code running on an interval:
Title pretty much covers it. If I've added say 3 objects to a list
Sorry, I am pretty much an SQL noob. This has to work in MSFT
I'm probably totally betraying my ignorance at this point, but I have pretty much

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.