MimePartCollection.Insert Method
Adds the specified MimePart to the MimePartCollection at the specified index.
[Visual Basic] Public Sub Insert( _ ByVal index As Integer, _ ByVal mimePart As MimePart _ ) [C#] public void Insert( int index, MimePart mimePart ); [C++] public: void Insert( int index, MimePart* mimePart ); [JScript] public function Insert( index : int, mimePart : MimePart );
Parameters
- index
- The zero-based index at which to insert the mimePart parameter.
- mimePart
- The MimePart to add to the collection.
Exceptions
| Exception Type | Condition |
|---|---|
| IndexOutOfRangeException | The index parameter is less than zero.
- or - The index parameter is greater than Count. |
Remarks
If the number of items in the collection already equals the collection's capacity, the capacity is doubled by automatically reallocating the internal array before the new element is inserted.
If the index parameter is equal to Count, the mimePart parameter is added to the end of the MimePartCollection.
The elements after the insertion point move down to accommodate the new element.
Example
[Visual Basic, C#, C++] The following example demonstrates a typical use of the Insert method.
[Visual Basic] Dim myMimeMultipartRelatedBinding As MimeMultipartRelatedBinding = Nothing Dim myIEnumerator As IEnumerator = myOutputBinding.Extensions.GetEnumerator() While myIEnumerator.MoveNext() myMimeMultipartRelatedBinding = CType(myIEnumerator.Current, MimeMultipartRelatedBinding) End While ' Create an instance of 'MimePartCollection'. Dim myMimePartCollection As New MimePartCollection() myMimePartCollection = myMimeMultipartRelatedBinding.Parts Console.WriteLine("Total number of mimepart elements in the collection initially" + _ " is: " + myMimePartCollection.Count.ToString()) ' Get the type of first 'Item' in collection. Console.WriteLine("The first object in collection is of type: " + _ myMimePartCollection.Item(0).ToString()) Dim myMimePart1 As New MimePart() ' Create an instance of 'MimeXmlBinding'. Dim myMimeXmlBinding1 As New MimeXmlBinding() myMimeXmlBinding1.Part = "body" myMimePart1.Extensions.Add(myMimeXmlBinding1) ' a mimepart at first position. myMimePartCollection.Insert(0, myMimePart1) Console.WriteLine("Inserting a mimepart object...") ' Check whether 'Insert' was successful or not. If myMimePartCollection.Contains(myMimePart1) Then ' Display the index of inserted 'MimePart'. Console.WriteLine("'MimePart' is succesfully inserted at position: " + _ myMimePartCollection.IndexOf(myMimePart1).ToString()) End If [C#] MimeMultipartRelatedBinding myMimeMultipartRelatedBinding = null; IEnumerator myIEnumerator = myOutputBinding.Extensions.GetEnumerator(); while(myIEnumerator.MoveNext()) { myMimeMultipartRelatedBinding=(MimeMultipartRelatedBinding)myIEnumerator.Current; } // Create an instance of 'MimePartCollection'. MimePartCollection myMimePartCollection = new MimePartCollection(); myMimePartCollection= myMimeMultipartRelatedBinding.Parts; Console.WriteLine("Total number of mimepart elements in the collection initially"+ " is: " +myMimePartCollection.Count); // Get the type of first 'Item' in collection. Console.WriteLine("The first object in collection is of type: " +myMimePartCollection[0].ToString()); MimePart myMimePart1=new MimePart(); // Create an instance of 'MimeXmlBinding'. MimeXmlBinding myMimeXmlBinding1 = new MimeXmlBinding(); myMimeXmlBinding1.Part = "body"; myMimePart1.Extensions.Add(myMimeXmlBinding1); // a mimepart at first position. myMimePartCollection.Insert(0,myMimePart1); Console.WriteLine("Inserting a mimepart object..."); // Check whether 'Insert' was successful or not. if(myMimePartCollection.Contains(myMimePart1)) { // Display the index of inserted 'MimePart'. Console.WriteLine("'MimePart' is succesfully inserted at position: " +myMimePartCollection.IndexOf(myMimePart1)); } [C++] MimeMultipartRelatedBinding* myMimeMultipartRelatedBinding = 0; IEnumerator* myIEnumerator = myOutputBinding->Extensions->GetEnumerator(); while(myIEnumerator->MoveNext()) myMimeMultipartRelatedBinding = dynamic_cast<MimeMultipartRelatedBinding*>(myIEnumerator->Current); // Create an instance of 'MimePartCollection'. MimePartCollection* myMimePartCollection = new MimePartCollection(); myMimePartCollection= myMimeMultipartRelatedBinding->Parts; Console::WriteLine(S"Total number of mimepart elements in the collection initially is: {0}", __box(myMimePartCollection->Count)); // Get the type of first 'Item' in collection. Console::WriteLine(S"The first object in collection is of type: {0}", myMimePartCollection->Item[0]); MimePart* myMimePart1 = new MimePart(); // Create an instance of 'MimeXmlBinding'. MimeXmlBinding* myMimeXmlBinding1 = new MimeXmlBinding(); myMimeXmlBinding1->Part = S"body"; myMimePart1->Extensions->Add(myMimeXmlBinding1); // a mimepart at first position. myMimePartCollection->Insert(0, myMimePart1); Console::WriteLine(S"Inserting a mimepart object..."); // Check whether 'Insert' was successful or not. if (myMimePartCollection->Contains(myMimePart1)) { // Display the index of inserted 'MimePart'. Console::WriteLine(S"'MimePart' is succesfully inserted at position: {0}", __box(myMimePartCollection->IndexOf(myMimePart1))); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family
See Also
MimePartCollection Class | MimePartCollection Members | System.Web.Services.Description Namespace