//Main
FileStream stream = null;
string UploadFileName = @"C:\sample.wsp";
FileInfo fileInfo = new FileInfo(UploadFileName);
//Verifying the condition whether that file is existed (or) not
if (!fileInfo.Exists) { throw new InvalidOperationException("The file does not exist."); }
byte[] bytes = System.IO.File.ReadAllBytes(fileInfo.Name);
//If file existed converting it in to the stream to transfer
stream = File.OpenRead(UploadFileName);
stream.Position = 0;
//usage
AddSolutionWorker("sample.wsp",bytes)
//Method
public void AddSolutionWorker(string wspName, byte[] wspcontents)
{
string tdir = Path.GetDirectoryName(Path.GetTempFileName());
string wsppath = string.Format(@"{0}\{1}", tdir, wspName);
if (File.Exists(wsppath))
File.Delete(wsppath);
File.WriteAllBytes(wsppath, wspcontents);
SPFarm.Local.Solutions.Add(wsppath);
File.Delete(wsppath);
}
No comments:
Post a Comment