当前位置: 首页>>代码示例>>C#>>正文


C# DirectoryInfo.Create方法代码示例

本文整理汇总了C#中System.IO.DirectoryInfo.Create方法的典型用法代码示例。如果您正苦于以下问题:C# DirectoryInfo.Create方法的具体用法?C# DirectoryInfo.Create怎么用?C# DirectoryInfo.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.DirectoryInfo的用法示例。


在下文中一共展示了DirectoryInfo.Create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Resize

        public static void Resize(this Image source, String newFilename, Size newSize, long quality, ContentAlignment contentAlignment, ThumbMode mode)
        {
            Image image = source.Resize(newSize, quality, contentAlignment, mode);

            using (EncoderParameters encoderParams = new EncoderParameters(1))
            {
                using (EncoderParameter parameter = (encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, quality)))
                {
                    ImageCodecInfo encoder = null;
                    //取得擴展名
                    string ext = Path.GetExtension(newFilename);
                    if (string.IsNullOrEmpty(ext))
                        ext = ".jpg";
                    //根據擴展名得到解碼、編碼器
                    foreach (ImageCodecInfo codecInfo in ImageCodecInfo.GetImageEncoders())
                    {
                        if (Regex.IsMatch(codecInfo.FilenameExtension, string.Format(@"(;|^)\*\{0}(;|$)", ext), RegexOptions.IgnoreCase))
                        {
                            encoder = codecInfo;
                            break;
                        }
                    }

                    DirectoryInfo dir = new DirectoryInfo(Path.GetDirectoryName(newFilename));
                    if(dir.Exists == false) dir.Create();
                    image.Save(newFilename, encoder, encoderParams);
                }
            }
        }
开发者ID:JasonSoft,项目名称:JasonSoft,代码行数:29,代码来源:DrawingExtension.cs

示例2: btnUpload_Click

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            lb_notvalid.Visible = false;

            if (FileUpload1.HasFile)
            {
                Guid g = Guid.NewGuid();
                DirectoryInfo updir = new DirectoryInfo(Server.MapPath("/media/upload/" + g));

                if (!updir.Exists)
                    updir.Create();

                FileUpload1.SaveAs(updir.FullName + "/" + FileUpload1.FileName);

                if (IsValidImage(updir.FullName + "/" + FileUpload1.FileName))
                {

                    tb_url.Text = "/media/upload/" + g + "/" +
                        ResizeImage(updir.FullName + "/", FileUpload1.FileName,
                        500, 1000, true);
                }
                else
                {
                    lb_notvalid.Visible = true;
                }
            }
        }
开发者ID:Jeavon,项目名称:OurUmbraco,代码行数:27,代码来源:InsertImage.ascx.cs

示例3: CreateDirectoryIfNotExists

 private static void CreateDirectoryIfNotExists(DirectoryInfo directoryInfo)
 {
     if(!directoryInfo.Exists) {
         CreateDirectoryIfNotExists(directoryInfo.Parent);
         directoryInfo.Create();
     }
 }
开发者ID:penartur,项目名称:FLocal,代码行数:7,代码来源:UploadHandler.cs

示例4: AtualizarGaleiraFotos

        public JsonResult AtualizarGaleiraFotos(string galeriaFotosUID,int IdProduto)
        {
            var direcotryTemp = new DirectoryInfo(Server.MapPath(string.Concat(ConfigurationManager.AppSettings["CaminhoImagensProduto"],"/temp/", galeriaFotosUID)));
            var directoryProd = new DirectoryInfo(Server.MapPath(string.Concat(ConfigurationManager.AppSettings["CaminhoImagensProduto"],"/", IdProduto.ToString())));

            if (!directoryProd.Exists)
                directoryProd.Create();
            else
            {
                directoryProd.Delete(true);
                directoryProd.Create();
            }

            foreach(var ft in direcotryTemp.GetFiles())
            {
                var newFile = string.Concat(directoryProd.FullName,"\\",ft.Name);
                ft.MoveTo(newFile);
            }

            direcotryTemp.Delete(true);

            return Json(new
            {
                TipoMensagem = TipoMensagemRetorno.Ok,
                Mensagem = "Operação Realizada com sucesso!",
            }, "text/html", JsonRequestBehavior.AllowGet);
        }
开发者ID:rodolpholl,项目名称:bakerymanager,代码行数:27,代码来源:CadastroProdutoController.cs

示例5: RecreateFolder

 public static void RecreateFolder(DirectoryInfo directoryInfo)
 {
     if (!directoryInfo.Exists)
     {
         directoryInfo.Create();
     }
     else
     {
         directoryInfo.Delete(true);
         directoryInfo.Create();
     }
 }
开发者ID:cybcaoyibo,项目名称:TerminologyLauncher,代码行数:12,代码来源:FolderUtils.cs

示例6: EntriesSetup

		public void EntriesSetup()
		{
			createEntries = new DirectoryInfo(Path.Combine(this.testContent.FullName, "CreateEntries"));
			// delete old entries
			if (createEntries.Exists)
			{
				createEntries.Delete(true);
				createEntries.Create();
			}
			else
			{
				createEntries.Create();
			}
		}
开发者ID:plntxt,项目名称:dasblog,代码行数:14,代码来源:BlogDataServiceTests.cs

示例7: ReplEditor

        /// <summary>
        /// Initializes a new instance of the <see cref="ReplEditor"/> class.
        /// </summary>
        public ReplEditor()
            : base(null)
        {
            this.Caption = "Repl Script Editor for Visual Studio - " + typeof(ReplEditor).Assembly.GetName().Version.ToString();
            //deploy sample script if needed
            var di = new DirectoryInfo(VSTools.ScriptsDirectory);
            if (!di.Exists) di.Create();

            var fileName = VSTools.DefaultScriptFileName;
            if (!File.Exists(fileName))
            {
                var assembly = Assembly.GetExecutingAssembly();
                var resourceName = "VSReplPackage.SampleScript.cs";

                using (Stream stream = assembly.GetManifestResourceStream(resourceName))
                using (StreamReader reader = new StreamReader(stream))
                {
                    string s = reader.ReadToEnd();
                    File.WriteAllText(fileName, s, Encoding.UTF8);
                }
            }
            // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
            // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
            // the object returned by the Content property.
            //this.Content = new ReplEditorControl();
            //init services
        }
开发者ID:pgourlain,项目名称:VSREPL,代码行数:30,代码来源:ReplEditor.cs

示例8: DumpData

        public void DumpData()
        {
            List<Microsoft.Research.Kinect.Nui.Vector> verts = convertRealDepth();
            DirectoryInfo root = new DirectoryInfo("./Dump");
            if(!root.Exists){
                root.Create();
            }

            int ct = 1;
            FileInfo file = new FileInfo(root.FullName + "/" + "dump_0.obj");
            while(file.Exists){
                file = new FileInfo(root.FullName + "/" + "dump_" + ct.ToString() + ".obj");
                ct++;
            }
            Console.WriteLine("Mesh Saved: {0}",file.FullName);
            List<Microsoft.Research.Kinect.Nui.Vector> tmp = new List<Microsoft.Research.Kinect.Nui.Vector>(points);
            using (StreamWriter sw = new StreamWriter(file.FullName))
            {
                foreach (Microsoft.Research.Kinect.Nui.Vector v in tmp)
                {
                    sw.WriteLine("v " + v.X.ToString() + " " + v.Y.ToString() + " " + v.Z.ToString());
                }

            }
        }
开发者ID:Jerdak,项目名称:KinectDaemon,代码行数:25,代码来源:UIDepthViewer.xaml.cs

示例9: ensureExists

 private void ensureExists(DirectoryInfo toDir)
 {
     if (toDir.Exists == false)
     {
         toDir.Create();
     }
 }
开发者ID:heikomilke,项目名称:shrew-PhotoCopy,代码行数:7,代码来源:MigrationProcess.cs

示例10: CopyDirectory

        /// <summary>
        /// Recursively copies a directory.
        /// </summary>
        /// <param name="sourceDirectory">The source directory to copy.</param>
        /// <param name="destinationDirectory">The destination directory.</param>
        /// <returns><see langword="true"/> if the copy is completed; otherwise <see langword="false"/>.</returns>
        public static bool CopyDirectory(string sourceDirectory, string destinationDirectory)
        {
            bool copyComplete = false;
            DirectoryInfo sourceDirectoryInfo = new DirectoryInfo(sourceDirectory);
            DirectoryInfo destinationDirectoryInfo = new DirectoryInfo(destinationDirectory);

            if (sourceDirectoryInfo.Exists)
            {
                if (!destinationDirectoryInfo.Exists)
                {
                    destinationDirectoryInfo.Create();
                }

                foreach (FileInfo fileEntry in sourceDirectoryInfo.GetFiles())
                {
                    fileEntry.CopyTo(Path.Combine(destinationDirectoryInfo.FullName, fileEntry.Name));
                }

                foreach (DirectoryInfo directoryEntry in sourceDirectoryInfo.GetDirectories())
                {
                    if (!CopyDirectory(directoryEntry.FullName, Path.Combine(destinationDirectoryInfo.FullName, directoryEntry.Name)))
                    {
                        copyComplete = false;
                    }
                }
            }

            copyComplete = true;
            return copyComplete;
        }
开发者ID:Zekom,项目名称:selenium,代码行数:36,代码来源:FileUtilities.cs

示例11: Initialize

 public bool Initialize(DirectoryInfo directory, Random r, out string reason)
 {
     try
     {
         string path = Path.Combine(directory.FullName, "races");
         DirectoryInfo di = new DirectoryInfo(path);
         if (!di.Exists)
         {
             //If it don't exist, create one so users can add races
             di.Create();
         }
         foreach (FileInfo fi in di.GetFiles("*.xml"))
         {
             Race race = new Race();
             if (!race.Initialize(fi, r, out reason))
             {
                 return false;
             }
             Races.Add(race);
         }
         reason = null;
         return true;
     }
     catch (Exception e)
     {
         reason = e.Message;
         return false;
     }
 }
开发者ID:rjaxon,项目名称:beyond-beyaan,代码行数:29,代码来源:RaceManager.cs

示例12: CheckDialogSaveFolder

        public void CheckDialogSaveFolder()
        {
            string today = "";
            string month = "";
            string dialogDir = "";
            DirectoryInfo resultDirInfo = null;
            try
            {
                today = DateTime.Now.ToShortDateString();
                month = today.Substring(0, 7);
                dialogDir = string.Format(WeDoCommon.ConstDef.MSGR_DATA_DLOG_DIR, ConfigHelper.Id)
                     + month + "\\" + today;

                resultDirInfo = new DirectoryInfo(dialogDir);
                if (!resultDirInfo.Exists)
                {
                    resultDirInfo.Create();
                    Logger.info(string.Format(" 대화저장폴더[{0}] 생성", dialogDir));
                }
            }
            catch (Exception e)
            {
                Logger.error(string.Format(" 대화저장폴더[{0}] 생성 실패:", dialogDir) + e.ToString());
            };
            
        }
开发者ID:WeDoCrm,项目名称:WeDoMessenger2.0,代码行数:26,代码来源:MiscController.cs

示例13: CreateFlags

		private void CreateFlags( DirectoryInfo dir )
		{
			DirectoryInfo readDir = new DirectoryInfo( Path.Combine( dir.FullName, "gfx/flags" ).Replace( '\\', '/' ) );

			string writeDirStr = Path.Combine( m_options.Data.MyDocsDir.FullName, m_options.Mod.Path );
			writeDirStr = Path.Combine( writeDirStr, "gfx/flags" ).Replace( '\\', '/' );
			DirectoryInfo writeDir = new DirectoryInfo( writeDirStr );

			if( !readDir.Exists )
				return;

			if( TaskStatus.Abort )
				return;
			if( !writeDir.Exists )
				writeDir.Create();

			CreateFlagsFromCounties( writeDir, readDir );

			if( TaskStatus.Abort )
				return;
			CreateFlagsFromDuchies( writeDir, readDir );

			if( TaskStatus.Abort )
				return;
			CreateFlagsFromKingdoms( writeDir, readDir );
		}
开发者ID:Measter,项目名称:TitleGenerator,代码行数:26,代码来源:FlagTask.cs

示例14: CreateFolder

        protected void CreateFolder()
        {
            try
            {

                string Serverpath = System.Configuration.ConfigurationManager.AppSettings["FolderPath"];
                string sDirPath = Server.MapPath("/"+Serverpath+"/");
                DirectoryInfo ObjSearchDir = new DirectoryInfo(sDirPath);

                if (!ObjSearchDir.Exists)
                {
                    ObjSearchDir.Create();
                    //Random number folder for file uploading

                    hdnUploadFilePath.Value = sDirPath;
                }
                else
                {
                    hdnUploadFilePath.Value = sDirPath;
                    // hdnFileFolder.Value = "0";
                }

            }
            catch (Exception mEx)
            {

            }
        }
开发者ID:rameshthanus,项目名称:ERP,代码行数:28,代码来源:Email.aspx.cs

示例15: CopyFolder

 private void CopyFolder(string from, string to)
 {
     try
     {
         DirectoryInfo source = new DirectoryInfo(from);
         DirectoryInfo destination = new DirectoryInfo(to);
         string fullpath;
         if (!destination.Exists)
             destination.Create();
         FileInfo[] Files = source.GetFiles();
         foreach (FileInfo fi in Files)
         {
             fullpath = Path.Combine(destination.FullName, fi.Name);
             fi.CopyTo(fullpath, true);
             this.counter++;
             int p = (this.counter * 100) / this.total;
             this.Worker.ReportProgress(p, fullpath);
         }
         // for subfolders
         DirectoryInfo[] folders = source.GetDirectories();
         foreach (DirectoryInfo folder in folders)
         {
             //construct new destination
             string newdestination = Path.Combine(destination.FullName, folder.Name);
             //recursive CopyFolder()
             CopyFolder(folder.FullName, newdestination);
         }
     }
     catch (Exception e)
     {
         Exceptioner.Log(e);
     }
 }
开发者ID:NithinKharvi,项目名称:moo-plus,代码行数:33,代码来源:TemplateDialog.cs


注:本文中的System.IO.DirectoryInfo.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。