本文整理汇总了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);
}
}
}
示例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;
}
}
}
示例3: CreateDirectoryIfNotExists
private static void CreateDirectoryIfNotExists(DirectoryInfo directoryInfo)
{
if(!directoryInfo.Exists) {
CreateDirectoryIfNotExists(directoryInfo.Parent);
directoryInfo.Create();
}
}
示例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);
}
示例5: RecreateFolder
public static void RecreateFolder(DirectoryInfo directoryInfo)
{
if (!directoryInfo.Exists)
{
directoryInfo.Create();
}
else
{
directoryInfo.Delete(true);
directoryInfo.Create();
}
}
示例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();
}
}
示例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
}
示例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());
}
}
}
示例9: ensureExists
private void ensureExists(DirectoryInfo toDir)
{
if (toDir.Exists == false)
{
toDir.Create();
}
}
示例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;
}
示例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;
}
}
示例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());
};
}
示例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 );
}
示例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)
{
}
}
示例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);
}
}