K? lai ?ifr?tu un at?ifr?tu faila pielikumu programmiski, izmantojot Visual c# programm? InfoPath 2003

Rakstu tulkojumi Rakstu tulkojumi
Raksta ID: 892730 - Apskatiet produktus, uz kuriem attiecas ?is raksts.
Izv?rst visu | Sak?aut visu

?aj? lap?

KOPSAVILKUMS

Microsoft Office InfoPath 2007 vai Microsoft Office InfoPath 2003 Service Pack 1 (SP1) var izmantot, Faila pielikumu vad?klu, InfoPath veidlapas veidnei pievienot failu. ?pa?os apst?k?os, ieteicams, lai ?ifr?tu un at?ifr?tu tad faila, kas pievienots Faila pielikumu kontroli. ?aj? gad?jum? j?s varat izmantot Microsoft Visual C# izveidot Kod?t?js klases un Dekod?t?js klases. P?c tam varat izmantot Kod?t?js klases un Dekod?t?js klases, lai ?ifr?tu un at?ifr?tu failu pielikumu.

IEVADS

?aj? rakst? ir aprakst?ti k? lai ?ifr?tu un at?ifr?tu faila pielikumu programmiski, izmantojot Microsoft Visual C# programm? InfoPath 2003. Papildinform?ciju, k? to izdar?t, InfoPath 2010 vai InfoPath 2007 skat?t ??du web lapu: K? kod??anas un dekod??anas faila pielikumu programmiski, izmantojot Visual c# InfoPath 2010 vai InfoPath 2007.

PAPILDINDORM?CIJA

Microsoft pied?v? programm??anas piem?rus tikai ilustr?cija bez izteiktas vai netie?as garantijas. Tas ietver, bet neaprobe?ojas ar netie??m garantij?m par piem?rot?bu p?rdo?anai vai atbilst?bu noteiktam m?r?is. ?aj? rakst? tiek pie?emts, ka esat iepazinies ar programmas valodu, kas tiek pier?d?ta un ar r?kiem, ko izmanto, lai izveidotu un atk??do?anas proced?ras. Microsoft atbalsta in?enieri var pal?dz?t izskaidrot funkcionalit?ti konkr?taj? proced?r?, ta?u vi?i nemain?s ?os piem?ri, kas neveidos jaunas proced?ras, kas atbilstu j?su ?pa?as pras?bas.

Visual c# InfoPath 2003 projekta izveide

  1. Start?t Microsoft Visual Studio.NET 2003.
  2. Par Failu izv?lni, noklik??iniet uzJaunu, un p?c tam noklik??iniet uz Projekts.
  3. Programm? Jauns projekts dialoglodzi??, noklik??iniet uzVisual c# projektiem programm? Microsoft Office InfoPath projektus mapi.
  4. Programm? v?rds lodzi?? ierakstietAttachmentEncoding, un p?c tam noklik??iniet uzlabi.
  5. Microsoft Office Project vedn? noklik??iniet uzIzveidotu jaunu veidlapas veidni, un p?c tam noklik??iniet uzApdare.

    Microsoft Office Project vednis izveido jaunu Visual Studio.NET 2003 projekts, kas saucas AttachmentEncoding. An Ar? izveidot InfoPath veidlapas veidni. InfoPath veidlapas veidne ir nosaukts AttachmentEncoding.

Izveidot Visual Studio Encoder klas?.NET 2003

  1. Solution Explorer, ar peles labo poguAttachmentEncoding, nor?diet uz Pievienot, un p?c tam noklik??iniet uz Pievienot jaunu vienumu.
  2. Programm? Pievienot jaunu vienumu dialoglodzi??, noklik??iniet uzKlase programm? Veidne: r?ts tipsInfoPathAttachmentEncoder.cs programm?v?rds r?ti?u un p?c tam noklik??iniet uz Atv?rt.
  3. Aizst?t visu kodu InfoPathAttachmentEncoder.cs failu ar ??du kodu.
    using System;
    using System.IO;
    using System.Text;
    using System.Security.Cryptography;
    
    namespace InfoPathAttachmentEncoding
    {
    	/// <summary>
    	/// InfoPathAttachment encodes file data into the format expected by InfoPath for use in file attachment nodes.
    	/// </summary>
    	public class InfoPathAttachmentEncoder
    	{
    		private string base64EncodedFile = string.Empty;
    		private string fullyQualifiedFileName;
    
    		/// <summary>
    		/// Creates an encoder to create an InfoPath attachment string.
    		/// </summary>
    		/// <param name="fullyQualifiedFileName"></param>
    		public InfoPathAttachmentEncoder(string fullyQualifiedFileName)
    		{
    			if (fullyQualifiedFileName == string.Empty)
    				throw new ArgumentException("Must specify file name", "fullyQualifiedFileName");
    
    			if (!File.Exists(fullyQualifiedFileName))
    				throw new FileNotFoundException("File does not exist: " + fullyQualifiedFileName, fullyQualifiedFileName);
    
    			this.fullyQualifiedFileName = fullyQualifiedFileName;
    		}
    
    		/// <summary>
    		/// Returns a Base64 encoded string.
    		/// </summary>
    		/// <returns>String</returns>
    		public string ToBase64String()
    		{
    			if (base64EncodedFile != string.Empty)
    				return base64EncodedFile;
    
    			// This memory stream will hold the InfoPath file attachment buffer before Base64 encoding.
    			MemoryStream ms = new MemoryStream();
    
    			// Get the file information.
    			using (BinaryReader br = new BinaryReader(File.Open(fullyQualifiedFileName, FileMode.Open, FileAccess.Read, FileShare.Read)))
    			{
    				string fileName = Path.GetFileName(fullyQualifiedFileName);
    
    				uint fileNameLength = (uint)fileName.Length + 1;
    
    				byte[] fileNameBytes = Encoding.Unicode.GetBytes(fileName);
    
    				using (BinaryWriter bw = new BinaryWriter(ms))
    				{
    					// Write the InfoPath attachment signature. 
    					bw.Write(new byte[] { 0xC7, 0x49, 0x46, 0x41 });
    
    					// Write the default header information.
    					bw.Write((uint)0x14);	// size
    					bw.Write((uint)0x01);	// version
    					bw.Write((uint)0x00);	// reserved
    
    					// Write the file size.
    					bw.Write((uint)br.BaseStream.Length);
    
    					// Write the size of the file name.
    					bw.Write((uint)fileNameLength);
    
    					// Write the file name (Unicode encoded).
    					bw.Write(fileNameBytes);
    
    					// Write the file name terminator. This is two nulls in Unicode.
    					bw.Write(new byte[] {0,0});
    
    					// Iterate through the file reading data and writing it to the outbuffer.
    					byte[] data = new byte[64*1024];
    					int bytesRead = 1;
    
    					while (bytesRead > 0)
    					{
    						bytesRead = br.Read(data, 0, data.Length);
    						bw.Write(data, 0, bytesRead);
    					}
    				}
    			}
    
    
    			// This memorystream will hold the Base64 encoded InfoPath attachment.
    			MemoryStream msOut = new MemoryStream();
    
    			using (BinaryReader br = new BinaryReader(new MemoryStream(ms.ToArray())))
    			{
    				// Create a Base64 transform to do the encoding.
    				ToBase64Transform tf = new ToBase64Transform();
    
    				byte[] data = new byte[tf.InputBlockSize];
    				byte[] outData = new byte[tf.OutputBlockSize];
    
    				int bytesRead = 1;
    
    				while (bytesRead > 0)
    				{
    					bytesRead = br.Read(data, 0, data.Length);
    
    					if (bytesRead == data.Length)
    						tf.TransformBlock(data, 0, bytesRead, outData, 0);
    					else
    						outData = tf.TransformFinalBlock(data, 0, bytesRead);
    
    					msOut.Write(outData, 0, outData.Length);
    				}
    			}
    
    			msOut.Close();
    			
    			return base64EncodedFile = Encoding.ASCII.GetString(msOut.ToArray());
    		}
    	}
    }

Izveidot Visual Studio Decoder klas?.NET 2003

  1. Solution Explorer, ar peles labo poguAttachmentEncoding, nor?diet uz Pievienot, un p?c tam noklik??iniet uz Pievienot jaunu vienumu.
  2. Programm? Pievienot jaunu vienumu dialoglodzi??, noklik??iniet uzKlase programm? Veidne: r?ts tipsInfoPathAttachmentDecoder.cs programm?v?rds r?ti?u un p?c tam noklik??iniet uz Atv?rt.
  3. Aizst?t visu kodu InfoPathAttachmentDecoder.cs failu ar ??du kodu.
    using System;
    using System.IO;
    using System.Text;
    
    namespace InfoPathAttachmentEncoding
    {
    	/// <summary>
    	/// Decodes a file attachment and saves it to a specified path.
    	/// </summary>
    	public class InfoPathAttachmentDecoder
    	{
    		private const int SP1Header_Size = 20;
    		private const int FIXED_HEADER = 16;
    
    		private int fileSize;
    		private int attachmentNameLength;
    		private string attachmentName;
    		private byte[] decodedAttachment;
    
    		/// <summary>
    		/// Accepts the Base64 encoded string
    		/// that is the attachment.
    		/// </summary>
    		public InfoPathAttachmentDecoder(string theBase64EncodedString)
    		{
    			byte [] theData = Convert.FromBase64String(theBase64EncodedString);
    			using(MemoryStream ms = new MemoryStream(theData))
    			{
    				BinaryReader theReader = new BinaryReader(ms);			
    				DecodeAttachment(theReader);
    			}
    		}
    
    		private void DecodeAttachment(BinaryReader theReader)
    		{
    			//Position the reader to get the file size.
    			byte[] headerData = new byte[FIXED_HEADER];
    			headerData = theReader.ReadBytes(headerData.Length);
    
    			fileSize = (int)theReader.ReadUInt32();
    			attachmentNameLength = (int)theReader.ReadUInt32() * 2;
    			
    			byte[] fileNameBytes = theReader.ReadBytes(attachmentNameLength);
    			//InfoPath uses UTF8 encoding.
    			Encoding enc = Encoding.Unicode;
    			attachmentName = enc.GetString(fileNameBytes, 0, attachmentNameLength - 2);
    			decodedAttachment = theReader.ReadBytes(fileSize);
    		}
    
    		public void SaveAttachment(string saveLocation)
    		{
    			string fullFileName = saveLocation;
    			if(!fullFileName.EndsWith(Path.DirectorySeparatorChar))
    			{
    				fullFileName += Path.DirectorySeparatorChar;
    			}
    
    			fullFileName += attachmentName;
    
    			if(File.Exists(fullFileName))
    				File.Delete(fullFileName);
    			
    			FileStream fs = new FileStream(fullFileName, FileMode.CreateNew);
    			BinaryWriter bw = new BinaryWriter(fs);
    			bw.Write(decodedAttachment);
    
    			bw.Close();
    			fs.Close();
    		}
    
    		public string Filename
    		{
    			get{ return attachmentName; }
    		}
    
    		public byte[] DecodedAttachment
    		{
    			get{ return decodedAttachment; }
    		}
    	}	
    }
    
    

Pievienojiet vad?klas faila pielikums un tekstlodzi?a vad?klu InfoPath veidlapas

  1. AttachmentEncoding InfoPath veidlapas veidn? noklik??iniet uz Vad?klas programm? Noform?juma uzdevumus uzdevumu r?t?.
  2. Programm? Vad?klasuzdevumr?ti, noklik??iniet uzFailu Pielikums zemIevietot vad?klas.
  3. Ar peles labo pogu noklik??iniet uz Faila pielikumu vad?klu, un p?c tam noklik??iniet uz Faila pielikuma rekviz?ti.
  4. Programm? Faila pielikuma rekviz?ti dialogu lodzi?? ierakstiet theAttachmentField programm? Lauk? v?rds r?ti?u un p?c tam noklik??iniet uz labi.
  5. Programm? Vad?klasuzdevumr?ti, noklik??iniet uzTekstlodzi?u zemIevietot vad?klas.
  6. Ar peles labo pogu noklik??iniet uz Tekstlodzi?u vad?klu, un p?c tam noklik??iniet uz Tekstlodzi?a rekviz?ti.
  7. Programm? Tekstlodzi?a rekviz?ti dialoglodzi??, tips theAttachmentName programm? Lauk? v?rds r?ti?u un p?c tam noklik??iniet uz labi.

Pievienot pogu Pievienot InfoPath veidlapas

  1. Programm? Vad?klasuzdevumr?ti, noklik??iniet uzPoga zemIevietot vad?klas.
  2. Ar peles labo pogu noklik??iniet uz jaun? Poga vad?klu, un p?c tam noklik??iniet uz Pogas Rekviz?ti.
  3. Programm? Pogas Rekviz?ti dialoga lodzi?? ierakstietPievienot programm? Eti?ete lodzi?? ierakstietbtnAttach programm? ID r?ti?u un p?c tam noklik??iniet uzRedi??t formas kodu.
  4. Pievienot ??du kodu sav? btnAttach_OnClick metodi.
    //Get a reference to the attachment node.
    IXMLDOMNode theAttachmentNode = thisXDocument.DOM.selectSingleNode("my:myFields/my:theAttachmentField");
    
    //Get a reference to the filename node.
    IXMLDOMNode fileNameNode = thisXDocument.DOM.selectSingleNode("my:myFields/my:theAttachmentName");
    //Get the text of the node.
    String fileName = fileNameNode.text;
    if(fileName.Length > 0)
    {
    	//Encode the file and assign it to the attachment node.
    	InfoPathAttachmentEncoding.Encoder myEncoder = new InfoPathAttachmentEncoding.Encoder(fileName);
    	if(theAttachmentNode.attributes.getNamedItem("xsi:nil") != null)
    		theAttachmentNode.attributes.removeNamedItem("xsi:nil");
    	theAttachmentNode.text = myEncoder.ToBase64String();
    }	
    

Pievienot pogu Saglab?t InfoPath veidlapas

  1. P?rsl?dzieties uz AttachmentEncoding InfoPath formas veidni.
  2. Programm? Vad?klasuzdevumr?ti, noklik??iniet uzPoga zemIevietot vad?klas.
  3. Ar peles labo pogu noklik??iniet uz jaun? Poga vad?klu, un p?c tam noklik??iniet uz Pogas Rekviz?ti.
  4. Programm? Pogas Rekviz?ti dialoga lodzi?? ierakstietSaglab?t programm? Eti?ete lodzi?? ierakstietbtnSave programm? ID r?ti?u un p?c tam noklik??iniet uzRedi??t formas kodu.
  5. Pievienot ??du kodu sav? btnSave _OnClick metodi.
    //Get a reference to the attachment node.
    IXMLDOMNode n = thisXDocument.DOM.selectSingleNode("my:myFields/my:theAttachmentField");
    //Get the text of the node.
    String theAttachment = n.text;
    if(theAttachment.Length > 0)
    {
    	InfoPathAttachmentEncoding.Decoder myDecoder = new InfoPathAttachmentEncoding.Decoder(theAttachment);
    	myDecoder.SaveAttachment(@"<Path to save the file>");
    }			
    
    Piez?me ?o kodu aizst?j <Path to="" save="" the="" file=""></Path> ar vietu, kur j?saglab? failu.

P?rliecinieties, ka InfoPath veidlapas veidn? ir piln?gi uzticamu

Pirms j?s varat p?rbaud?t ?o veidlapu, InfoPath veidlapas veidnei j?b?t piln?gi uzticamas. Var izmantot vienu no ??m metod?m, lai p?rliecin?tos, vai InfoPath veidlapas veidn? ir piln?b? uzticams:
  • Izmantot Microsoft.NET Framework 1.1 konfigur??anas util?ta lai pie??irtu piln?gas uzticam?bas at?aujas tikai Visual C# kodu.
  • Izmantojiet util?tu RegForm, no programmas InfoPath Izstr?des komplekta (SDK) lai padar?tu veidlapu piln?b? uzticamas veidlapas. Tas pie??ir pilnu Uzticam?bas at?aujas Visual C# kodu.
  • Izmantot, lai digit?li parakst?tu veidlapu koda parakst??anas sertifik?ts veidnes fails (. xsn). Izmantojot koda parakst??anas sertifik?ts, lai digit?li parakst?tu veidlapas veidnes fails, lietot?ji sa?em aicin?jumu uztic?ties formu, atverot formu. Tas padara piln?gi uzticamas veidlapas. T?d?? ir piln?gas uzticam?bas at?aujas pie??irt Visual C# kodu.
  • Lieto?anas IPFullTrust makro no InfoPath SDK, lai piln?gi uzticamu veidlapu formu. Uz IPFullTrust makro automatiz? manifesta (. xsf) faila un veidlapas veidnes failu programm? InfoPath projektu piln?gu uzticam?bu, un p?c tam IPFullTrust makro autom?tiski re?istr? veidlapas veidni.

    Par Pla??ku inform?ciju par to, k? instal?t un izmantot ?o makro, apmekl?jiet ?o Microsoft Developer Network (MSDN) vietni:
    http://msdn2.Microsoft.com/en-us/library/aa202736 (office.11). aspx
  • Izmantot ?r?jo automatiz?cija programm? InfoPath, lai izsauktu RegisterSolution metodi. Parasti ?o metodi izmanto tikai veidlapu izstr?de jo juridisk? forma tikai re?istros atsevi??os datoros. Jebkuram papildu veidlapu citiem lietot?jiem j?re?istr?jas papildu veidlap?m, par to pa?u datoriem. M?s neiesak?m ?o metodi attiec?b? uz papildu form?m. M?s iesak?m k?da no iepriek? min?taj?m metod?m, public?jot formas.
T? k? ?? forma ir izstr?d?tas veidlapas, var izmantot p?d?j? metode. Lai to izdar?tu, atrodiet AttachmentEncoding InfoPath veidlapas veidni, un p?c tam r?kojieties ??di:
  1. Par R?ki izv?lni, noklik??iniet uz Forma Opcijas.
  2. Noklik??iniet uz Dro??bas TAB.
  3. Noklik??iniet, lai not?r?tu Autom?tiski noteikt dro??bas l?meni, kas pamatojas uz veidlapas noform?jumu (ieteicams) izv?les r?ti?u.

    Piez?me Programma InfoPath nevar autom?tiski noteikt, biznesa lo?iku, kas pieprasa piln?gas uzticam?bas at?aujas. T?d?? ir j?pie??ir tie?i pilna Uzticam?bas at?aujas.
  4. Noklik??iniet uz Piln?gas uzticam?bas, un p?c tam noklik??iniet uzlabi.
  5. Aizveriet AttachmentEncoding InfoPath veidlapas veidni. Ja tiek pied?v?ts saglab?t veikt?s izmai?as, noklik??iniet uz j?.

    Piez?me Neaizveriet Visual Studio.NET 2003 projekts.
  6. Visual Studio.NET 2003, veiciet dubultklik??i uzManifest. xsf Solution Explorer failu. Manifest. xsf failu atver.
  7. Saknes mezglu, atrodiet publishUrl atrib?ts. No?emt publishUrl atrib?tu un v?rt?bu publishUrl atrib?ts.
  8. Saglab?jiet izmai?as un p?c tam aizveriet manifest. xsf failu.
  9. Noklik??iniet uz S?kums, noklik??iniet uz Palaist, tips Piez?mjbloks, un p?c tam noklik??iniet uzlabi.
  10. Tuk?u teksta failu, pievienot ??du kodu.
    oApp = WScript.CreateObject("InfoPath.ExternalApplication");
    strAbsolutePath = "<project_folder_url>\\Manifest.xsf";
    oApp.RegisterSolution(strAbsolutePath,"overwrite"); 
    
    Piez?me ?o kodu aizst?j<project_folder_url></project_folder_url> ar ce?u Manifest. xsf failu projekta map?. Atcer?ties ce?u b?gt Manifest. xsf fail?. Visas vienu atpaka?v?rsto sl?psv?tru (\) ce?? ir j?nomaina ar divas atpaka?v?rst?s sl?psv?tras (\).
  11. Saglab?t dator? k? manifest. xsf failu Register.js failu.
  12. Lai piezvan?tu RegisterSolution metodi, veiciet dubultklik??i uz Register.js fails, kas esat izveidojis.

P?rbaud?t veidlapu

  1. AttachmentEncoding Visual Studio.NET 2003 projekta noklik??iniet uz S?kums par Atk??do?anas izv?lne. Tas s?kas InfoPath veidlapu priek?skat?juma re??m?.
  2. InfoPath veidlapas, ievadiet faila ce?u, kas pievienojiet tekstlodzi?u un p?c tam noklik??iniet uzPievienot.

    Piez?me Veiciet dubultklik??i uz Faila pielikumu vad?klu, lai P?rbaudiet, vai fails ir pareizi kod?ta.
  3. Noklik??iniet uz Saglab?t. Atrodiet ce?u, kuru sniegta "pievienot Saglab?t pogas InfoPath veidlapas" sada??.
  4. Lai beigtu test??anu, noklik??iniet uz Aizveriet Priek?skat?jums.

UZZI?AS

Pla??ku inform?ciju par faila pielikuma virsraksta form?t?, apmekl?jiet ?o MSDN Web vietu:
Pievienot failus programm? InfoPath 2003
http://msdn2.Microsoft.com/en-us/library/aa168351 (office.11). aspx

Rekviz?ti

Raksta ID: 892730 - P?d?jo reizi p?rskat?ts: pirmdiena, 2012. gada 5. marts - P?rskat??ana: 0.1
ATTIECAS UZ:
  • Microsoft Office InfoPath 2003
Atsl?gv?rdi: 
kbcode kbscript kbsample kbxml kbprogramming kbhowto kbmt KB892730 KbMtlv
Ma??ntulko?ana
SVAR?GI! ?is raksts ir tulkots, izmantojot Microsoft ma??ntulko?anas programmat?ru, un ?o rakstu nav tulkojis cilv?ks. Microsoft pied?v? gan rakstus, ko tulkoju?i cilv?ki, gan ma??ntulkotus rakstus, t?p?c jebkuram zin??anu b?zes rakstam varat piek??t sav? dzimtaj? valod?. Tom?r ma??ntulkotu rakstu kvalit?te ne vienm?r ir teicama. ??dos rakstos var b?t leksikas, sintakses vai gramatikas k??das, kas l?dzin?s k??d?m, k?das pie?auj ?rzemnieks, run?jot j?su valod?. Microsoft neuz?emas atbild?bu par jebk?d?m neprecizit?t?m, k??d?m vai boj?jumiem, ko izrais?jis k??dains satura tulkojums vai kas radu??s tulkojuma lietojuma gait?. Turkl?t Microsoft regul?ri atjaunina ma??ntulko?anas programmat?ru.
Noklik??iniet ?eit, lai skat?tu ?? raksta versiju ang?u valod?: 892730

Sniegt atsauksmes

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com