title: How to write two record to NFC tag, one Custom URI and one Text data?
body: <p>I wrote a small test application using the "<a href="https://ndef.codeplex.com/" rel="nofollow">NDEF Library for Proximity APIs / NFC</a>" in codeplex.</p>
  
  <p>I am writing 2 records into a tag: the first record is NdefUriRecord with custom scheme and the second is NdefTextRecord. </p>
  
  <p>When tapping the NFC tag, my test application starts as exprected (based on the scheme defined in the first record).</p>
  
  <p>However in order for my application to read the second record on the tag (after being started automatically), I have to move the tag away and re-tap, otherwise the application will not read the tag's second record.</p>
  
  <p>Is this a normal behavior? How can I overcome this issue?</p>
  
  <p>If anybody has another way to put 2 records on a tag, one custom URI record to start the application and the second a Text record to have some JSON data (as text) please let me know.</p>
  
  <p>Thanks,</p>
  
  <pre><code>using System.Diagnostics;
  using System.Windows;
  using System.Windows.Navigation;
  using Microsoft.Phone.Controls;
  using Windows.Networking.Proximity;
  using NdefLibrary.Ndef;
  using System.Runtime.InteropServices.WindowsRuntime;
  using Microsoft.Phone.Tasks;
  
  namespace NfcShare
      {
      public partial class MainPage : PhoneApplicationPage
          {
          private ProximityDevice _device;
          long _subscribedMessageId;
  
          // Constructor
          public MainPage()
              {
              InitializeComponent();
  
              // -&gt; Initialize proximity device
              _device = ProximityDevice.GetDefault();
  
              TxtStatus.Text = "Initialized";
              }
  
          private void LogStatusMessage( string newStatus )
              {
              // Update the status output UI element in the UI thread
              // (some of the callbacks are in a different thread that wouldn't be allowed
              // to modify the UI thread)
              Dispatcher.BeginInvoke( () =&gt;
                                          {
                                              if ( TxtStatus != null ) TxtStatus.Text = newStatus;
                                          } );
              }
  
  
          private void MessageWrittenHandler( ProximityDevice sender, long messageId )
              {
              LogStatusMessage( "Message published!" );
              _device.StopPublishingMessage( messageId );
              }
  
          // -----------------------------------------------------------------------------------
          // Custom URI Scheme
  
          // -&gt; Override OnNavigatedTo() and check QueryString
          protected override void OnNavigatedTo( NavigationEventArgs e )
              {
              base.OnNavigatedTo( e );
  
              if ( NavigationContext.QueryString.ContainsKey( "ms_nfp_launchargs" ) )
                  {
                  LogStatusMessage( "Launched Args: " + NavigationContext.QueryString[ "ms_nfp_launchargs" ] );
                  }
              } 
  
          // -----------------------------------------------------------------------------------
          // Write tags 
          private void BtnWriteTag_Click( object sender, RoutedEventArgs e )
              {
              NdefUriRecord rec1 = new NdefUriRecord
                                      {
                                          Uri = "nfcshare:Hello+World"
                                      };
  
              NdefTextRecord rec2 = new NdefTextRecord();
              rec2.Text = "Record 2";
  
              NdefMessage msg = new NdefMessage();
  
              msg.Add( rec1 );
              msg.Add( rec2 );
  
              _device.PublishBinaryMessage(
                  "NDEF:WriteTag",
                  msg.ToByteArray().AsBuffer(),
                  MessageWrittenHandler );
  
              LogStatusMessage( "Publishing message ..." );
              } 
  
          // -----------------------------------------------------------------------------------
          // Read tags
          private void BtnSubscribeTag_Click( object sender, RoutedEventArgs e )
              {
              _subscribedMessageId = _device.SubscribeForMessage( "NDEF", MessageReceivedHandler );
              LogStatusMessage( "Subscribed for tag ..." );
              }
  
          private void MessageReceivedHandler( ProximityDevice sender, ProximityMessage message )
              {
              var rawMsg = message.Data.ToArray();
              var ndefMessage = NdefMessage.FromByteArray( rawMsg );
  
              // Loop over all records contained in the NDEF message
              foreach ( NdefRecord record in ndefMessage )
                  {
                  if ( NdefUriRecord.IsRecordType( record ) )
                      {
                      // Convert and extract URI info
                      var uriRecord = new NdefUriRecord( record );
                      LogStatusMessage( "Read tag, URI: " + uriRecord.Uri );
                      }
                  else if ( NdefTextRecord.IsRecordType( record ) )
                      {
                      // Convert and extract URI info
                      var textRecord = new NdefTextRecord( record );
                      LogStatusMessage( "Read tag, Text: " + textRecord.Text );
                      }
                  }
              // Only read one tag
              _device.StopSubscribingForMessage( _subscribedMessageId );
              }
          }
      }
  </code></pre>