Click here to Skip to main content
12,447,242 members (66,160 online)

SharePoint

 
QuestionDeleting Items in a SPListItemCollection Pin
Aptiva Dave31-Jan-13 5:05
memberAptiva Dave31-Jan-13 5:05 
AnswerRe: Deleting Items in a SPListItemCollection Pin
JimmyRopes7-Feb-13 1:39
memberJimmyRopes7-Feb-13 1:39 
QuestionGetting an error when trying to upload a document Pin
JimmyRopes30-Jan-13 2:35
memberJimmyRopes30-Jan-13 2:35 
AnswerRe: Getting an error when trying to upload a document Pin
ihoecken30-Jan-13 2:50
memberihoecken30-Jan-13 2:50 
GeneralRe: Getting an error when trying to upload a document Pin
JimmyRopes30-Jan-13 4:03
memberJimmyRopes30-Jan-13 4:03 
AnswerRe: Getting an error when trying to upload a document Pin
ihoecken30-Jan-13 4:55
memberihoecken30-Jan-13 4:55 
AnswerRe: Getting an error when trying to upload a document Pin
ihoecken30-Jan-13 2:57
memberihoecken30-Jan-13 2:57 
GeneralRe: Getting an error when trying to upload a document Pin
JimmyRopes30-Jan-13 4:05
memberJimmyRopes30-Jan-13 4:05 
QuestionRequest for Sharepoint tutorial links Pin
obalesu28-Jan-13 18:18
memberobalesu28-Jan-13 18:18 
AnswerRe: Request for Sharepoint tutorial links Pin
ihoecken28-Jan-13 21:13
memberihoecken28-Jan-13 21:13 
QuestionCan CAML query handle multiple lists? Pin
Clark Kent12328-Jan-13 5:35
memberClark Kent12328-Jan-13 5:35 
AnswerRe: Can CAML query handle multiple lists? Pin
ihoecken28-Jan-13 21:17
memberihoecken28-Jan-13 21:17 
GeneralRe: Can CAML query handle multiple lists? Pin
Clark Kent12329-Jan-13 1:34
memberClark Kent12329-Jan-13 1:34 
QuestionThrowing an exception when trying to attach a document to a list item Pin
JimmyRopes25-Jan-13 2:34
memberJimmyRopes25-Jan-13 2:34 
I am throwing a System.ArgumentException when trying to attach a document to a list item.

This is the code I am using. I had log statements (since removed to eliminate extraneous code) that showed me that I was getting to the
Item.Attachments.AddNow(FileName, binFile);
statement which was throwing the exception.

The variable "FileName" is passed as a parameter of type String to the web service.

The list has attachments enabled.

Can anyone spot what I am doing wrong?

// open prototype site and web
site = new SPSite(SPContext.Current.Web.Url);
web = site.OpenWeb("cabinet");
SPSite oSite = null;
SPWeb oWeb = null;
 
if (0 < Id.Length
 && 0 < FileName.Length)
{
    try
    {
        SPSecurity.RunWithElevatedPrivileges(delegate()
        {
            using (oSite = new SPSite(site.ID))
            {
                using (oWeb = oSite.OpenWeb(web.ID))
                {
                    oWeb.AllowUnsafeUpdates = true;
 
                    SPQuery query = new SPQuery();
                    query.Query = String.Concat(
                        "<Where>",
                                    "<Eq>",
                                    "<FieldRef Name=\"ItemNumber\" />",
                                    "<Value Type=\"Number\">" + Id + "</Value>",
                                    "</Eq>",
                        "</Where>");
                    query.ViewFields = "<FieldRef Name=\"ItemNumber\" />";
                    query.RowLimit = 1;
                    SPListItemCollection listItems = oWeb.Lists["ListName"].GetItems(query);
                    // perform if item returned
                    foreach (SPListItem Item in listItems)
                    {
                        try
                        {
                        String FilePath = String.Format("{0}{1}", Server.MapPath("~/_doc_uploads/"), FileName);
                            FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
                            byte[] binFile = new byte[fs.Length];
                            fs.Read(binFile, 0, System.Convert.ToInt32(fs.Length));
                            fs.Close();
                            fs.Dispose();
                            Item.Attachments.AddNow(FileName, binFile);
                            Item.Update();
                        } // try
                        catch (Exception ex)
                        {
                            Log.WriteExceptionInfo(ex);
                        }
                    } // foreach (SPListItem Item in listItems)
                    oWeb.AllowUnsafeUpdates = false;
                } // using (SPWeb oWeb = oSite.OpenWeb(web.ID))
            } // using (SPSite oSite = new SPSite(site.ID))
        }); // SPSecurity.RunWithElevatedPrivileges(delegate()
        returnData.Status = 0;
        returnData.Id = Id;
    } // try
    catch (Exception ex)
    {
        returnData.Status = 30;
        returnData.Msg = String.Format("{0}\n\nContact technical support and inform them of the error you have received.", ex.Message);
        Log.WriteLine(ex.Message);
        Log.WriteExceptionInfo(ex);
    } // catch (Exception ex)
    finally
    {
        if (oWeb != null) oWeb.Dispose();
        if (oSite != null) oSite.Dispose();
        if (web != null) web.Dispose();
        if (site != null) site.Dispose();
    } // finally
} // if (0 < Id.Length etc.

This is the exception that is thrown.

1/24/2013 14:20:33.3051534 - --------- Exception Data ---------
Message: Value does not fall within the expected range.
Exception Type: System.ArgumentException
Source: Microsoft.SharePoint
StrackTrace:    at Microsoft.SharePoint.SPFieldMap.GetColumnNumber(String strFieldName)
   at Microsoft.SharePoint.SPListItemCollection.GetRawValue(String fieldname, Int32 iIndex)
   at Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32 columnNumber, Boolean bRaw)
   at Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean bThrowException)
   at Microsoft.SharePoint.SPListItem.GetValue(String strName)
   at Microsoft.SharePoint.SPListItem.get_Attachments()
   at nsDashboardSpServices.DashboardSpServices.<>c__DisplayClass82.<addLoaAttachment>b__7e()
TargetSite: Int32 GetColumnNumber(System.String)

The report of my death was an exaggeration - Mark Twain

Simply Elegant Designs JimmyRopes Designs
Think inside the box! ProActive Secure Systems

I'm on-line therefore I am.
JimmyRopes


AnswerRe: Throwing an exception when trying to attach a document to a list item Pin
Aptiva Dave31-Jan-13 5:07
memberAptiva Dave31-Jan-13 5:07 
GeneralRe: Throwing an exception when trying to attach a document to a list item Pin
JimmyRopes31-Jan-13 13:30
memberJimmyRopes31-Jan-13 13:30 
GeneralRe: Throwing an exception when trying to attach a document to a list item Pin
JimmyRopes7-Feb-13 2:31
memberJimmyRopes7-Feb-13 2:31 
QuestionHo to Enable Titlle Column in Document Library using power shell in sharepoint 2010 Pin
ps4124-Jan-13 18:21
memberps4124-Jan-13 18:21 
AnswerRe: Ho to Enable Titlle Column in Document Library using power shell in sharepoint 2010 Pin
ihoecken24-Jan-13 22:06
memberihoecken24-Jan-13 22:06 
QuestionHow to intergrade Sarepoint contacts with MS exchange server? Pin
cns connect20-Jan-13 21:57
membercns connect20-Jan-13 21:57 
AnswerRe: How to intergrade Sarepoint contacts with MS exchange server? Pin
ihoecken20-Jan-13 23:44
memberihoecken20-Jan-13 23:44 
QuestionExternal content type crawlling sharepoint 2013 Pin
Member 401525120-Jan-13 8:40
memberMember 401525120-Jan-13 8:40 
Questionsharepoint 2010 birthday reminder webpart Pin
ssivarao17-Jan-13 1:13
memberssivarao17-Jan-13 1:13 
AnswerRe: sharepoint 2010 birthday reminder webpart Pin
ihoecken20-Jan-13 23:42
memberihoecken20-Jan-13 23:42 
Questionform Infopath Pin
zohre yousefi16-Jan-13 20:12
memberzohre yousefi16-Jan-13 20:12 
AnswerRe: form Infopath Pin
ihoecken16-Jan-13 23:24
memberihoecken16-Jan-13 23:24 
QuestionHow do I add a drop down list to the New Item... Pin
Clark Kent12315-Jan-13 8:50
memberClark Kent12315-Jan-13 8:50 
AnswerRe: How do I add a drop down list to the New Item... Pin
Clark Kent12316-Jan-13 7:06
memberClark Kent12316-Jan-13 7:06 
QuestionCannot connect to business data connectivity Metadata store Sharepoint designer 2013 Pin
Member 401525113-Jan-13 18:56
memberMember 401525113-Jan-13 18:56 
AnswerRe: Cannot connect to business data connectivity Metadata store Sharepoint designer 2013 Pin
Clark Kent12315-Jan-13 8:42
memberClark Kent12315-Jan-13 8:42 
GeneralRe: Cannot connect to business data connectivity Metadata store Sharepoint designer 2013 Pin
Member 401525115-Jan-13 22:19
memberMember 401525115-Jan-13 22:19 
QuestionPossible write a TimeSheet Program using SharePoint2010 Pin
Gabriel Yeung10-Jan-13 22:49
memberGabriel Yeung10-Jan-13 22:49 
AnswerRe: Possible write a TimeSheet Program using SharePoint2010 Pin
ihoecken10-Jan-13 23:23
memberihoecken10-Jan-13 23:23 
QuestionAutomatic Upload Script in SharePoint 2007 Pin
mbadi8-Jan-13 18:30
membermbadi8-Jan-13 18:30 
AnswerRe: Automatic Upload Script in SharePoint 2007 Pin
ihoecken8-Jan-13 20:34
memberihoecken8-Jan-13 20:34 
QuestionAggregate lists with JavaScript Pin
garfield1853-Jan-13 3:14
membergarfield1853-Jan-13 3:14 
AnswerRe: Aggregate lists with JavaScript Pin
ihoecken7-Jan-13 2:42
memberihoecken7-Jan-13 2:42 
Questionchange publish location infopath 2010 Pin
rehabreda29-Dec-12 1:28
memberrehabreda29-Dec-12 1:28 
AnswerRe: change publish location infopath 2010 Pin
ihoecken7-Jan-13 2:36
memberihoecken7-Jan-13 2:36 
GeneralRe: change publish location infopath 2010 Pin
rehabreda8-Jan-13 22:29
memberrehabreda8-Jan-13 22:29 
Questionhow to send an email alert everyday at 12:00 PM Pin
sai.201226-Dec-12 11:19
membersai.201226-Dec-12 11:19 
AnswerRe: how to send an email alert everyday at 12:00 PM Pin
ihoecken7-Jan-13 2:30
memberihoecken7-Jan-13 2:30 
QuestionGet image from clip board Pin
MShinde225-Dec-12 22:26
memberMShinde225-Dec-12 22:26 
SuggestionRe: Get image from clip board Pin
ihoecken8-Jan-13 20:40
memberihoecken8-Jan-13 20:40 
QuestionDebugging question Pin
Aptiva Dave20-Dec-12 11:04
memberAptiva Dave20-Dec-12 11:04 
AnswerRe: Debugging question Pin
ihoecken7-Jan-13 2:59
memberihoecken7-Jan-13 2:59 
GeneralRe: Debugging question Pin
Aptiva Dave7-Jan-13 3:12
memberAptiva Dave7-Jan-13 3:12 
GeneralRe: Debugging question Pin
ihoecken7-Jan-13 3:15
memberihoecken7-Jan-13 3:15 
Questionto create a Leave approval workflow where User submit leave request Pin
sai.201218-Dec-12 16:12
membersai.201218-Dec-12 16:12 
AnswerRe: to create a Leave approval workflow where User submit leave request Pin
ihoecken18-Dec-12 23:42
memberihoecken18-Dec-12 23:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.160811.3 | Last Updated 18 Aug 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid